schema_to_dbml 0.0.6 → 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: 0d0ac5d45ffc3f45685848a61f55084656c7ca61c9f35c7adf37fd1ba35408ab
4
- data.tar.gz: 26cedb4c8356f33d854a8a9e351ec2c1691dab71127bbedd67551ab55e20bfdb
3
+ metadata.gz: 4108364b1e7c9cd89e4ae413c1282b2140bcb6b4ce5758eeb37ded7eabe26dcf
4
+ data.tar.gz: 9ad7bf887518c4cefdb84101e3ab5bd1c76876e973dd3d0fc49148739034cb2d
5
5
  SHA512:
6
- metadata.gz: a0860f6ab756779c7f90ebe1942c7a231687bb9c1f1e1ec86bf6b778b86423cd696a57b6695b9df82f75215cec1459ab8b6fdf9e9c16e807095874750114079a
7
- data.tar.gz: a2a47bef2c7719d060845cb516db62147aa8cc7736bd69ac9716d6afb102975c8df4ffcfca9bf70773c5db2cfa52ffe7f9d20170bb8d23b8553aa2619e516170
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
@@ -7,7 +7,7 @@ PATH
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.2.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)
@@ -71,7 +72,7 @@ GEM
71
72
  rubocop (~> 1.41)
72
73
  rubocop-factory_bot (2.25.1)
73
74
  rubocop (~> 1.41)
74
- rubocop-rspec (2.28.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)
@@ -85,6 +86,7 @@ GEM
85
86
  simplecov_json_formatter (~> 0.1)
86
87
  simplecov-html (0.12.3)
87
88
  simplecov_json_formatter (0.1.4)
89
+ strscan (3.1.0)
88
90
  tzinfo (2.0.6)
89
91
  concurrent-ruby (~> 1.0)
90
92
  unicode-display_width (2.5.0)
data/README.md CHANGED
@@ -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
@@ -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)
@@ -52,6 +52,8 @@ module Formatters
52
52
  note.gsub!(mapper[:from], mapper[:to])
53
53
  end
54
54
 
55
+ note = "#{note} " if note[-1, 1] == "'"
56
+
55
57
  "note: '''#{note}'''"
56
58
  end
57
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SchemaToDbml
4
- VERSION = '0.0.6'
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.6
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-04-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