schema_to_dbml 0.0.5 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc54963544b87bb99449b5bcb2129a64211378ffbfec57cfbbebce562bdf0c0b
4
- data.tar.gz: 06c18c1b57f71d0c064ae1d01ee2df9de0600bd68da6748c657af1f51f819927
3
+ metadata.gz: 4108364b1e7c9cd89e4ae413c1282b2140bcb6b4ce5758eeb37ded7eabe26dcf
4
+ data.tar.gz: 9ad7bf887518c4cefdb84101e3ab5bd1c76876e973dd3d0fc49148739034cb2d
5
5
  SHA512:
6
- metadata.gz: 7733b4a827bff5432bd663e6900f9c8cb7388b89b6eaabc7135cf01acfa09ff4f527262c127d9ec15fbe82cb5536a5fc96bf67511956572d34e78ae51c999a5f
7
- data.tar.gz: e86975d104f9cc120f6a20e88d6a412534ef9b47286940a08f2ebaf3ec5a1d59ff7a7d7280995ada45f1676b9b91437a39b380ee29ea6f41002c6ba56aa53ef5
6
+ metadata.gz: fc6519ae82320a59e075f63069455dec421c0cc4cfc15897a4d10dbb3a51d3a1e8ce8916efcddfa6075e44da2d6989613eea2c927efa26c0a1a56f5d5e8cef4f
7
+ data.tar.gz: 5748195dbe7347e88672f6ca0171cc4d00091a94cb6120d1a4c49780ba2461e0104542c36dbbcf9002f1468d4c5508e032a8be4009262ccf5f04dbbe8e39b062
data/.rubocop.yml CHANGED
@@ -81,3 +81,9 @@ Gemspec/DevelopmentDependencies:
81
81
 
82
82
  Metrics/ParameterLists:
83
83
  Max: 8
84
+
85
+ RSpec/NestedGroups:
86
+ Max: 4
87
+
88
+ RSpec/MessageSpies:
89
+ EnforcedStyle: receive
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- schema_to_dbml (0.0.5)
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.1.3.2)
10
+ activesupport (7.1.3.4)
11
11
  base64
12
12
  bigdecimal
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -19,18 +19,18 @@ GEM
19
19
  tzinfo (~> 2.0)
20
20
  ast (2.4.2)
21
21
  base64 (0.2.0)
22
- bigdecimal (3.1.6)
22
+ bigdecimal (3.1.8)
23
23
  byebug (11.1.3)
24
- concurrent-ruby (1.2.3)
24
+ concurrent-ruby (1.3.3)
25
25
  connection_pool (2.4.1)
26
26
  diff-lcs (1.5.1)
27
27
  docile (1.4.0)
28
28
  drb (2.2.1)
29
- i18n (1.14.1)
29
+ i18n (1.14.5)
30
30
  concurrent-ruby (~> 1.0)
31
- json (2.7.1)
31
+ json (2.7.2)
32
32
  language_server-protocol (3.17.0.3)
33
- minitest (5.22.2)
33
+ minitest (5.24.0)
34
34
  mutex_m (0.2.0)
35
35
  parallel (1.24.0)
36
36
  parser (3.3.0.5)
@@ -38,9 +38,10 @@ GEM
38
38
  racc
39
39
  racc (1.7.3)
40
40
  rainbow (3.1.1)
41
- rake (13.1.0)
41
+ rake (13.2.1)
42
42
  regexp_parser (2.9.0)
43
- rexml (3.2.6)
43
+ rexml (3.2.8)
44
+ strscan (>= 3.0.9)
44
45
  rspec (3.13.0)
45
46
  rspec-core (~> 3.13.0)
46
47
  rspec-expectations (~> 3.13.0)
@@ -54,7 +55,7 @@ GEM
54
55
  diff-lcs (>= 1.2.0, < 2.0)
55
56
  rspec-support (~> 3.13.0)
56
57
  rspec-support (3.13.0)
57
- rubocop (1.61.0)
58
+ rubocop (1.62.1)
58
59
  json (~> 2.3)
59
60
  language_server-protocol (>= 3.17.0)
60
61
  parallel (~> 1.10)
@@ -62,19 +63,22 @@ GEM
62
63
  rainbow (>= 2.2.2, < 4.0)
63
64
  regexp_parser (>= 1.8, < 3.0)
64
65
  rexml (>= 3.2.5, < 4.0)
65
- rubocop-ast (>= 1.30.0, < 2.0)
66
+ rubocop-ast (>= 1.31.1, < 2.0)
66
67
  ruby-progressbar (~> 1.7)
67
68
  unicode-display_width (>= 2.4.0, < 3.0)
68
- rubocop-ast (1.31.1)
69
+ rubocop-ast (1.31.2)
69
70
  parser (>= 3.3.0.4)
70
71
  rubocop-capybara (2.20.0)
71
72
  rubocop (~> 1.41)
72
73
  rubocop-factory_bot (2.25.1)
73
74
  rubocop (~> 1.41)
74
- rubocop-rspec (2.27.0)
75
+ rubocop-rspec (2.29.1)
75
76
  rubocop (~> 1.40)
76
77
  rubocop-capybara (~> 2.17)
77
78
  rubocop-factory_bot (~> 2.22)
79
+ rubocop-rspec_rails (~> 2.28)
80
+ rubocop-rspec_rails (2.28.2)
81
+ rubocop (~> 1.40)
78
82
  ruby-progressbar (1.13.0)
79
83
  simplecov (0.22.0)
80
84
  docile (~> 1.1)
@@ -82,6 +86,7 @@ GEM
82
86
  simplecov_json_formatter (~> 0.1)
83
87
  simplecov-html (0.12.3)
84
88
  simplecov_json_formatter (0.1.4)
89
+ strscan (3.1.0)
85
90
  tzinfo (2.0.6)
86
91
  concurrent-ruby (~> 1.0)
87
92
  unicode-display_width (2.5.0)
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
  ```
@@ -80,7 +80,7 @@ custom_project_notes: |
80
80
  custom_dbml_content: |
81
81
  enum object_status {
82
82
  created [note: 'Initial status']
83
- pending
83
+ pending
84
84
  finished
85
85
  cancelled
86
86
  }
@@ -89,6 +89,11 @@ custom_dbml_content: |
89
89
  table_2
90
90
  table_3
91
91
  }
92
+ custom_tables:
93
+ my_table:
94
+ attributes:
95
+ my_attribute:
96
+ type: object_status
92
97
  ```
93
98
 
94
99
  After that, you can use the SchemaToDbml to generate the DBML content as usual.
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require_relative 'lib/schema_to_dbml'
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
data/lib/configuration.rb CHANGED
@@ -8,6 +8,7 @@ class Configuration
8
8
  @custom_primary_key = yaml_data['custom_primary_key']
9
9
  @custom_project_name = yaml_data['custom_project_name']
10
10
  @custom_project_notes = yaml_data['custom_project_notes']
11
+ @custom_tables = yaml_data['custom_tables']
11
12
  end
12
13
 
13
14
  attr_accessor :custom_database_type,
@@ -15,5 +16,6 @@ class Configuration
15
16
  :custom_dbml_file_path,
16
17
  :custom_primary_key,
17
18
  :custom_project_name,
18
- :custom_project_notes
19
+ :custom_project_notes,
20
+ :custom_tables
19
21
  end
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :schema_to_dbml do
4
- desc 'build dmbl.yml'
5
- task :generate, %i[schema_path] => [:environment] do |_t, args|
4
+ desc 'Build dbml.yml'
5
+ task :generate, [:schema_path] do |_t, args|
6
6
  schema = args[:schema_path]
7
+ raise 'Schema path must be provided' unless schema
8
+
9
+ SchemaToDbml.load_configuration_from_yaml
7
10
  SchemaToDbml.new.generate(schema:)
8
11
  end
9
12
  end
@@ -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
@@ -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'
@@ -14,7 +14,7 @@ class DbmlTablesFormatter
14
14
  end
15
15
 
16
16
  def format(table_name:, table_comment:, table_attributes:)
17
- columns = build_columns(table_attributes)
17
+ columns = build_columns(table_name, table_attributes)
18
18
  indexes = build_indexes(table_attributes)
19
19
 
20
20
  format_dbml(table_name, columns, indexes, table_comment)
@@ -22,14 +22,16 @@ class DbmlTablesFormatter
22
22
 
23
23
  private
24
24
 
25
- def build_columns(table_attributes)
25
+ def build_columns(table_name, table_attributes)
26
26
  columns = []
27
27
 
28
+ custom_table_attributes = configuration.custom_tables&.dig(table_name, 'attributes')
28
29
  table_attributes.scan(COLUMNS_REGEXP).each do |type, name, default, null, comment, _precision, array, limit|
29
30
  formatted_comment = format_comment(comment:)
30
31
  formatted_default = format_default(default:)
31
32
  formatted_null = format_null(null:)
32
- formatted_type = format_type(type:, array:, limit:)
33
+ custom_type = custom_table_attributes&.dig(name, 'type')
34
+ formatted_type = format_type(type: custom_type || type, array:, limit:)
33
35
 
34
36
  final_values = [formatted_default, formatted_null, formatted_comment].compact.reject(&:empty?)
35
37
  columns << build_line(name, formatted_type, final_values)
@@ -63,7 +65,7 @@ class DbmlTablesFormatter
63
65
  dbml_table << "#{TAB}#{custom_primary_key}\n"
64
66
  dbml_table << columns.join("\n")
65
67
  dbml_table << indexes if indexes
66
- dbml_table << "\n#{TAB}Note: '#{table_comment}'" unless table_comment.to_s.empty?
68
+ dbml_table << "\n#{TAB}Note: '''#{table_comment}'''" unless table_comment.to_s.empty?
67
69
  dbml_table << "\n}"
68
70
  dbml_table
69
71
  end
@@ -52,7 +52,9 @@ module Formatters
52
52
  note.gsub!(mapper[:from], mapper[:to])
53
53
  end
54
54
 
55
- "note: '#{note}'"
55
+ note = "#{note} " if note[-1, 1] == "'"
56
+
57
+ "note: '''#{note}'''"
56
58
  end
57
59
  end
58
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SchemaToDbml
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.7'
5
5
  end
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.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Ribeiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-03 00:00:00.000000000 Z
11
+ date: 2024-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler