schema_to_dbml 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -3
- data/.rubocop_todo.yml +16 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +52 -29
- data/README.md +1 -1
- data/lib/schema_to_dbml/build_dbml_content.rb +1 -1
- data/lib/schema_to_dbml/build_dbml_file.rb +2 -2
- data/lib/schema_to_dbml/configs/custom_config.yml +1 -1
- data/lib/schema_to_dbml/dbml_tables_formatter.rb +24 -8
- data/lib/schema_to_dbml/formatters/fields_formatter.rb +2 -1
- data/lib/schema_to_dbml/formatters/index_formatter.rb +33 -0
- data/lib/schema_to_dbml/helpers/constants.rb +9 -1
- data/lib/schema_to_dbml/schema_converter.rb +2 -2
- data/lib/schema_to_dbml/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d0ac5d45ffc3f45685848a61f55084656c7ca61c9f35c7adf37fd1ba35408ab
|
4
|
+
data.tar.gz: 26cedb4c8356f33d854a8a9e351ec2c1691dab71127bbedd67551ab55e20bfdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0860f6ab756779c7f90ebe1942c7a231687bb9c1f1e1ec86bf6b778b86423cd696a57b6695b9df82f75215cec1459ab8b6fdf9e9c16e807095874750114079a
|
7
|
+
data.tar.gz: a2a47bef2c7719d060845cb516db62147aa8cc7736bd69ac9716d6afb102975c8df4ffcfca9bf70773c5db2cfa52ffe7f9d20170bb8d23b8553aa2619e516170
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-rspec
|
5
|
+
|
1
6
|
AllCops:
|
2
7
|
TargetRubyVersion: 3.1.2
|
3
8
|
Exclude:
|
4
|
-
- spec/
|
5
|
-
- spec/shared_examples/*
|
9
|
+
- spec/support/**/*
|
6
10
|
- vendor/bundle/**/*
|
7
11
|
NewCops: enable
|
8
12
|
|
@@ -71,7 +75,7 @@ Style/RedundantFetchBlock:
|
|
71
75
|
|
72
76
|
Style/MethodCallWithArgsParentheses:
|
73
77
|
Enabled: false
|
74
|
-
|
78
|
+
|
75
79
|
Gemspec/DevelopmentDependencies:
|
76
80
|
Enabled: false
|
77
81
|
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2024-03-03 11:08:02 UTC using RuboCop version 1.61.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
RSpec/MultipleExpectations:
|
11
|
+
Max: 3
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
# Configuration parameters: AllowSubject.
|
15
|
+
RSpec/MultipleMemoizedHelpers:
|
16
|
+
Max: 6
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.0
|
data/Gemfile.lock
CHANGED
@@ -1,62 +1,83 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
schema_to_dbml (0.0.
|
4
|
+
schema_to_dbml (0.0.6)
|
5
5
|
activesupport (>= 6.1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (7.
|
10
|
+
activesupport (7.1.3.2)
|
11
|
+
base64
|
12
|
+
bigdecimal
|
11
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
connection_pool (>= 2.2.5)
|
15
|
+
drb
|
12
16
|
i18n (>= 1.6, < 2)
|
13
17
|
minitest (>= 5.1)
|
18
|
+
mutex_m
|
14
19
|
tzinfo (~> 2.0)
|
15
20
|
ast (2.4.2)
|
21
|
+
base64 (0.2.0)
|
22
|
+
bigdecimal (3.1.6)
|
16
23
|
byebug (11.1.3)
|
17
|
-
concurrent-ruby (1.2.
|
18
|
-
|
24
|
+
concurrent-ruby (1.2.3)
|
25
|
+
connection_pool (2.4.1)
|
26
|
+
diff-lcs (1.5.1)
|
19
27
|
docile (1.4.0)
|
28
|
+
drb (2.2.1)
|
20
29
|
i18n (1.14.1)
|
21
30
|
concurrent-ruby (~> 1.0)
|
22
|
-
json (2.
|
31
|
+
json (2.7.1)
|
23
32
|
language_server-protocol (3.17.0.3)
|
24
|
-
minitest (5.
|
25
|
-
|
26
|
-
|
33
|
+
minitest (5.22.2)
|
34
|
+
mutex_m (0.2.0)
|
35
|
+
parallel (1.24.0)
|
36
|
+
parser (3.3.0.5)
|
27
37
|
ast (~> 2.4.1)
|
28
38
|
racc
|
29
|
-
racc (1.7.
|
39
|
+
racc (1.7.3)
|
30
40
|
rainbow (3.1.1)
|
31
|
-
rake (13.0
|
32
|
-
regexp_parser (2.
|
33
|
-
rexml (3.2.
|
34
|
-
rspec (3.
|
35
|
-
rspec-core (~> 3.
|
36
|
-
rspec-expectations (~> 3.
|
37
|
-
rspec-mocks (~> 3.
|
38
|
-
rspec-core (3.
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-expectations (3.
|
41
|
+
rake (13.2.0)
|
42
|
+
regexp_parser (2.9.0)
|
43
|
+
rexml (3.2.6)
|
44
|
+
rspec (3.13.0)
|
45
|
+
rspec-core (~> 3.13.0)
|
46
|
+
rspec-expectations (~> 3.13.0)
|
47
|
+
rspec-mocks (~> 3.13.0)
|
48
|
+
rspec-core (3.13.0)
|
49
|
+
rspec-support (~> 3.13.0)
|
50
|
+
rspec-expectations (3.13.0)
|
41
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.13.0)
|
53
|
+
rspec-mocks (3.13.0)
|
44
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-support (3.
|
47
|
-
rubocop (1.
|
55
|
+
rspec-support (~> 3.13.0)
|
56
|
+
rspec-support (3.13.0)
|
57
|
+
rubocop (1.62.1)
|
48
58
|
json (~> 2.3)
|
49
59
|
language_server-protocol (>= 3.17.0)
|
50
60
|
parallel (~> 1.10)
|
51
|
-
parser (>= 3.
|
61
|
+
parser (>= 3.3.0.2)
|
52
62
|
rainbow (>= 2.2.2, < 4.0)
|
53
63
|
regexp_parser (>= 1.8, < 3.0)
|
54
64
|
rexml (>= 3.2.5, < 4.0)
|
55
|
-
rubocop-ast (>= 1.
|
65
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
56
66
|
ruby-progressbar (~> 1.7)
|
57
67
|
unicode-display_width (>= 2.4.0, < 3.0)
|
58
|
-
rubocop-ast (1.
|
59
|
-
parser (>= 3.
|
68
|
+
rubocop-ast (1.31.2)
|
69
|
+
parser (>= 3.3.0.4)
|
70
|
+
rubocop-capybara (2.20.0)
|
71
|
+
rubocop (~> 1.41)
|
72
|
+
rubocop-factory_bot (2.25.1)
|
73
|
+
rubocop (~> 1.41)
|
74
|
+
rubocop-rspec (2.28.0)
|
75
|
+
rubocop (~> 1.40)
|
76
|
+
rubocop-capybara (~> 2.17)
|
77
|
+
rubocop-factory_bot (~> 2.22)
|
78
|
+
rubocop-rspec_rails (~> 2.28)
|
79
|
+
rubocop-rspec_rails (2.28.2)
|
80
|
+
rubocop (~> 1.40)
|
60
81
|
ruby-progressbar (1.13.0)
|
61
82
|
simplecov (0.22.0)
|
62
83
|
docile (~> 1.1)
|
@@ -66,10 +87,11 @@ GEM
|
|
66
87
|
simplecov_json_formatter (0.1.4)
|
67
88
|
tzinfo (2.0.6)
|
68
89
|
concurrent-ruby (~> 1.0)
|
69
|
-
unicode-display_width (2.
|
90
|
+
unicode-display_width (2.5.0)
|
70
91
|
|
71
92
|
PLATFORMS
|
72
93
|
arm64-darwin-21
|
94
|
+
arm64-darwin-23
|
73
95
|
x86_64-darwin-22
|
74
96
|
x86_64-linux
|
75
97
|
|
@@ -79,6 +101,7 @@ DEPENDENCIES
|
|
79
101
|
rake
|
80
102
|
rspec
|
81
103
|
rubocop
|
104
|
+
rubocop-rspec
|
82
105
|
schema_to_dbml!
|
83
106
|
simplecov
|
84
107
|
|
data/README.md
CHANGED
@@ -58,7 +58,7 @@ custom_project_notes: |
|
|
58
58
|
- Utilizes the custom primary key for better indexing
|
59
59
|
- Specifies the appropriate database type (e.g., PostgreSQL)
|
60
60
|
- Provides meaningful project information and descriptions
|
61
|
-
custom_primary_key: "id integer [pk, unique, note: 'Unique identifier and primary key']"
|
61
|
+
custom_primary_key: "id integer [pk, unique, note: '''Unique identifier and primary key''']"
|
62
62
|
custom_dbml_content: ''
|
63
63
|
custom_dbml_file_path: 'db/schema.dbml'
|
64
64
|
```
|
@@ -20,7 +20,7 @@ class BuildDbmlContent
|
|
20
20
|
def project_header
|
21
21
|
header = "Project #{project_name} {\n"
|
22
22
|
header += " database_type: '#{custom_database_type}'\n"
|
23
|
-
header += " Note: '#{custom_project_notes}'\n"
|
23
|
+
header += " Note: '''#{custom_project_notes}'''\n"
|
24
24
|
header += '}'
|
25
25
|
header
|
26
26
|
end
|
@@ -18,8 +18,8 @@ class SchemaConverter
|
|
18
18
|
def convert(schema_content:)
|
19
19
|
tables = []
|
20
20
|
relations = []
|
21
|
-
schema_content.scan(TABLES_REGEXP).each do |table_name, table_comment,
|
22
|
-
tables << dbml_tables_formatter.format(table_name:, table_comment:,
|
21
|
+
schema_content.scan(TABLES_REGEXP).each do |table_name, table_comment, table_attributes|
|
22
|
+
tables << dbml_tables_formatter.format(table_name:, table_comment:, table_attributes:)
|
23
23
|
end
|
24
24
|
|
25
25
|
schema_content.scan(RELATIONS_REGEXP).each do |from_table, to_table, column, on_delete|
|
@@ -7,6 +7,6 @@ custom_project_notes: |
|
|
7
7
|
- Utilizes the custom primary key for better indexing
|
8
8
|
- Specifies the appropriate database type (e.g., PostgreSQL)
|
9
9
|
- Provides meaningful project information and descriptions
|
10
|
-
custom_primary_key: "id integer [pk, unique, note: 'Unique identifier and primary key']"
|
10
|
+
custom_primary_key: "id integer [pk, unique, note: '''Unique identifier and primary key''']"
|
11
11
|
custom_dbml_content: ''
|
12
12
|
custom_dbml_file_path: 'db/schema.dbml'
|
@@ -1,28 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'formatters/fields_formatter'
|
4
|
+
require_relative 'formatters/index_formatter'
|
4
5
|
require_relative 'helpers/constants'
|
5
6
|
|
6
7
|
class DbmlTablesFormatter
|
7
8
|
include Helpers::Constants
|
8
9
|
include Formatters::FieldsFormatter
|
10
|
+
include Formatters::IndexFormatter
|
9
11
|
|
10
12
|
def initialize(configuration: SchemaToDbml.configuration)
|
11
13
|
@configuration = configuration
|
12
14
|
end
|
13
15
|
|
14
|
-
def format(table_name:, table_comment:,
|
15
|
-
columns = build_columns(
|
16
|
+
def format(table_name:, table_comment:, table_attributes:)
|
17
|
+
columns = build_columns(table_attributes)
|
18
|
+
indexes = build_indexes(table_attributes)
|
16
19
|
|
17
|
-
format_dbml(table_name, columns, table_comment)
|
20
|
+
format_dbml(table_name, columns, indexes, table_comment)
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
def build_columns(
|
25
|
+
def build_columns(table_attributes)
|
23
26
|
columns = []
|
24
27
|
|
25
|
-
|
28
|
+
table_attributes.scan(COLUMNS_REGEXP).each do |type, name, default, null, comment, _precision, array, limit|
|
26
29
|
formatted_comment = format_comment(comment:)
|
27
30
|
formatted_default = format_default(default:)
|
28
31
|
formatted_null = format_null(null:)
|
@@ -35,6 +38,18 @@ class DbmlTablesFormatter
|
|
35
38
|
columns
|
36
39
|
end
|
37
40
|
|
41
|
+
def build_indexes(table_definition)
|
42
|
+
indexes = []
|
43
|
+
|
44
|
+
table_definition.scan(INDEXES_REGEXP) do |columns, index_name, unique|
|
45
|
+
indexes << format_index(columns, index_name, unique)
|
46
|
+
end
|
47
|
+
|
48
|
+
return if indexes.empty?
|
49
|
+
|
50
|
+
"\n#{TAB}indexes {\n#{indexes.join("\n")}\n#{TAB}}"
|
51
|
+
end
|
52
|
+
|
38
53
|
def build_line(name, formatted_type, final_values)
|
39
54
|
line = " #{name} #{formatted_type}"
|
40
55
|
|
@@ -43,11 +58,12 @@ class DbmlTablesFormatter
|
|
43
58
|
line << " [#{final_values.join(',')}]"
|
44
59
|
end
|
45
60
|
|
46
|
-
def format_dbml(table_name, columns, table_comment)
|
61
|
+
def format_dbml(table_name, columns, indexes, table_comment)
|
47
62
|
dbml_table = "Table #{table_name} {\n"
|
48
|
-
dbml_table << "
|
63
|
+
dbml_table << "#{TAB}#{custom_primary_key}\n"
|
49
64
|
dbml_table << columns.join("\n")
|
50
|
-
dbml_table <<
|
65
|
+
dbml_table << indexes if indexes
|
66
|
+
dbml_table << "\n#{TAB}Note: '''#{table_comment}'''" unless table_comment.to_s.empty?
|
51
67
|
dbml_table << "\n}"
|
52
68
|
dbml_table
|
53
69
|
end
|
@@ -5,6 +5,7 @@ require_relative 'default_field_formatter_helper'
|
|
5
5
|
module Formatters
|
6
6
|
module FieldsFormatter
|
7
7
|
include DefaultFieldFormatterHelper
|
8
|
+
|
8
9
|
COMMENT_MAPPER = [
|
9
10
|
{ from: "'", to: "\\\\'" },
|
10
11
|
{ from: '\"', to: '"' }
|
@@ -51,7 +52,7 @@ module Formatters
|
|
51
52
|
note.gsub!(mapper[:from], mapper[:to])
|
52
53
|
end
|
53
54
|
|
54
|
-
"note: '#{note}'"
|
55
|
+
"note: '''#{note}'''"
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../helpers/constants'
|
4
|
+
|
5
|
+
module Formatters
|
6
|
+
module IndexFormatter
|
7
|
+
include Helpers::Constants
|
8
|
+
|
9
|
+
def format_index(columns, index_name, unique)
|
10
|
+
formatted_columns = format_index_columns(columns)
|
11
|
+
formatted_settings = format_index_settings(unique)
|
12
|
+
formatted_name = "name: '#{index_name}'"
|
13
|
+
formatted_values = [formatted_settings, formatted_name].compact.join(', ')
|
14
|
+
|
15
|
+
"#{TAB * 2}(#{formatted_columns}) [#{formatted_values}]"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def format_index_columns(columns)
|
21
|
+
columns.gsub('"', '').split(', ').join(', ')
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_index_settings(unique)
|
25
|
+
# There are other possible settings for indexes
|
26
|
+
# but for now we will only add unique
|
27
|
+
# https://dbml.dbdiagram.io/docs/#index-definition
|
28
|
+
return unless unique
|
29
|
+
|
30
|
+
'unique'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
module Helpers
|
4
4
|
module Constants
|
5
|
+
TAB = ' '
|
6
|
+
|
5
7
|
TABLES_REGEXP = /
|
6
8
|
create_table\s+"(?<table_name>\w+)"
|
7
9
|
(?:,\s+comment:\s+"(?<comment>.*?)")?
|
8
10
|
(?:,\s+force:\s+:cascade)?
|
9
11
|
\s+do\s+\|t\|
|
10
12
|
\n
|
11
|
-
(?<
|
13
|
+
(?<table_attributes>(?:.*?)(?:".*?")*.*?)
|
12
14
|
(?<=\n)
|
13
15
|
\s+end
|
14
16
|
/xm
|
@@ -25,6 +27,12 @@ module Helpers
|
|
25
27
|
)*
|
26
28
|
/x
|
27
29
|
|
30
|
+
INDEXES_REGEXP = /
|
31
|
+
t\.index\s+\[(?<columns>[^\]]+)\]
|
32
|
+
(?:,\s+name:\s+"(?<name>[^"\\]*(?:\\.[^"\\]*)*)")?
|
33
|
+
(?:,\s+unique:\s+(?<unique>true|false))?
|
34
|
+
/x
|
35
|
+
|
28
36
|
RELATIONS_REGEXP = /
|
29
37
|
add_foreign_key\s+"(?<from_table>\w+)",\s+"(?<to_table>\w+)"
|
30
38
|
(?:,\s+column:\s+"(?<column>\w+)")?
|
@@ -18,8 +18,8 @@ class SchemaConverter
|
|
18
18
|
def convert(schema_content:)
|
19
19
|
tables = []
|
20
20
|
relations = []
|
21
|
-
schema_content.scan(TABLES_REGEXP).each do |table_name, table_comment,
|
22
|
-
tables << dbml_tables_formatter.format(table_name:, table_comment:,
|
21
|
+
schema_content.scan(TABLES_REGEXP).each do |table_name, table_comment, table_attributes|
|
22
|
+
tables << dbml_tables_formatter.format(table_name:, table_comment:, table_attributes:)
|
23
23
|
end
|
24
24
|
|
25
25
|
schema_content.scan(RELATIONS_REGEXP).each do |from_table, to_table, column, on_delete|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_to_dbml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: simplecov
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,6 +132,7 @@ extra_rdoc_files: []
|
|
118
132
|
files:
|
119
133
|
- ".rspec"
|
120
134
|
- ".rubocop.yml"
|
135
|
+
- ".rubocop_todo.yml"
|
121
136
|
- ".ruby-version"
|
122
137
|
- CHANGELOG.md
|
123
138
|
- CODE_OF_CONDUCT.md
|
@@ -140,6 +155,7 @@ files:
|
|
140
155
|
- lib/schema_to_dbml/errors/schema_file_not_found_error.rb
|
141
156
|
- lib/schema_to_dbml/formatters/default_field_formatter_helper.rb
|
142
157
|
- lib/schema_to_dbml/formatters/fields_formatter.rb
|
158
|
+
- lib/schema_to_dbml/formatters/index_formatter.rb
|
143
159
|
- lib/schema_to_dbml/helpers/constants.rb
|
144
160
|
- lib/schema_to_dbml/schema_converter.rb
|
145
161
|
- lib/schema_to_dbml/version.rb
|
@@ -167,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
183
|
- !ruby/object:Gem::Version
|
168
184
|
version: '0'
|
169
185
|
requirements: []
|
170
|
-
rubygems_version: 3.3
|
186
|
+
rubygems_version: 3.5.3
|
171
187
|
signing_key:
|
172
188
|
specification_version: 4
|
173
189
|
summary: A Ruby on Rails gem for converting schema.rb files to DBML.
|