k_domain 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +31 -1
  3. data/STORIES.md +6 -2
  4. data/k_domain.gemspec +2 -0
  5. data/lib/k_domain/domain_model/dtos/_.rb +88 -0
  6. data/lib/k_domain/domain_model/dtos/belongs_to.rb +25 -0
  7. data/lib/k_domain/domain_model/dtos/column_old.rb +225 -0
  8. data/lib/k_domain/domain_model/dtos/dictionary/dictionary.rb +17 -0
  9. data/lib/k_domain/domain_model/dtos/domain.rb +11 -0
  10. data/lib/k_domain/domain_model/dtos/domain_statistics.rb +29 -0
  11. data/lib/k_domain/domain_model/dtos/entity.rb +338 -0
  12. data/lib/k_domain/domain_model/dtos/entity_statistics.rb +22 -0
  13. data/lib/k_domain/domain_model/dtos/foreign_key.rb +17 -0
  14. data/lib/k_domain/domain_model/dtos/has_and_belongs_to_many.rb +20 -0
  15. data/lib/k_domain/domain_model/dtos/has_many.rb +27 -0
  16. data/lib/k_domain/domain_model/dtos/has_one.rb +41 -0
  17. data/lib/k_domain/domain_model/dtos/investigate/investigate.rb +10 -0
  18. data/lib/k_domain/domain_model/dtos/investigate/issue.rb +13 -0
  19. data/lib/k_domain/domain_model/dtos/models/column.rb +49 -0
  20. data/lib/k_domain/domain_model/dtos/models/model.rb +111 -0
  21. data/lib/k_domain/domain_model/dtos/name_options.rb +10 -0
  22. data/lib/k_domain/domain_model/dtos/rails_controller.rb +10 -0
  23. data/lib/k_domain/domain_model/dtos/rails_model.rb +92 -0
  24. data/lib/k_domain/domain_model/dtos/related_entity.rb +36 -0
  25. data/lib/k_domain/domain_model/dtos/schema.rb +12 -0
  26. data/lib/k_domain/domain_model/dtos/statistics.rb +21 -0
  27. data/lib/k_domain/domain_model/dtos/validate.rb +25 -0
  28. data/lib/k_domain/domain_model/dtos/validates.rb +50 -0
  29. data/lib/k_domain/domain_model/load.rb +29 -0
  30. data/lib/k_domain/domain_model/transform.rb +94 -0
  31. data/lib/k_domain/domain_model/transform_steps/_.rb +9 -0
  32. data/lib/k_domain/domain_model/transform_steps/step.rb +123 -0
  33. data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +21 -0
  34. data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +62 -0
  35. data/lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb +137 -0
  36. data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +454 -0
  37. data/lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb +56 -0
  38. data/lib/k_domain/raw_db_schema/dtos/_.rb +14 -0
  39. data/lib/k_domain/raw_db_schema/dtos/column.rb +16 -0
  40. data/lib/k_domain/raw_db_schema/dtos/database.rb +11 -0
  41. data/lib/k_domain/raw_db_schema/dtos/foreign_key.rb +14 -0
  42. data/lib/k_domain/raw_db_schema/dtos/index.rb +14 -0
  43. data/lib/k_domain/raw_db_schema/dtos/schema.rb +18 -0
  44. data/lib/k_domain/raw_db_schema/dtos/table.rb +21 -0
  45. data/lib/k_domain/raw_db_schema/dtos/unique_key.rb +14 -0
  46. data/lib/k_domain/raw_db_schema/load.rb +29 -0
  47. data/lib/k_domain/{raw_schema → raw_db_schema}/template.rb +0 -0
  48. data/lib/k_domain/{raw_schema → raw_db_schema}/transform.rb +37 -21
  49. data/lib/k_domain/version.rb +1 -1
  50. data/lib/k_domain.rb +14 -1
  51. metadata +74 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a69b94955a43f91d71e034b94a5caf0d3fdbb7b130c480d4eabc45818bbe2262
4
- data.tar.gz: 0f4a126ee7c9bed5d99ac7449e5f97ec558030b126dbaa3c6194cdb5ce8430bd
3
+ metadata.gz: 92aebc822bef5bff0524221c4ca53f3bccdf4f3b4a134c2bcdd207f7c58e5609
4
+ data.tar.gz: db850d6a8d98ee6a5fd77f1cfe5a9e87d5da262ebec598c84f8ca70b3fb5a1cb
5
5
  SHA512:
6
- metadata.gz: 3a7a877e80c9f23cdb93ab7952e027bdddc89bd6e888212c6fc0622cc0d5ae6d9b73e3e9651949ecd1afa2f1323e6446045f579cb6e83c030c5d8d711979deaa
7
- data.tar.gz: 434275e01ec2308d4a1407f5e8bd7ab9ec9708218510b6a719c144e2d9b6abb7e2caafa67efc617ac33295cd276c2326ccd961468ee4870b38266ef1b1295296
6
+ metadata.gz: d31d1bd2e461d1a86b938eb043c9dda1c5f553e3a8a1ddd759e0ff24b349da2100f934feb0ac8b001da137086862145aa575be1a2b32a6070f1f82b5ff63a837
7
+ data.tar.gz: acd57f1f859401f1d0ff8f39fc7cc3eb69ee128a0c91b94f5ce92bb275ff82924663ce00beb58a25c19752934e2ccc70f1cf04a83e1b8de429e70bd403fb48eb
data/.rubocop.yml CHANGED
@@ -6,7 +6,26 @@ AllCops:
6
6
  NewCops: enable
7
7
  Exclude:
8
8
  - "_/**/*"
9
- - "spec/samples/**/*"
9
+ - "spec/sample_input/**/*"
10
+ - "spec/sample_output/**/*"
11
+ - "lib/k_domain/raw_db_schema/template.rb"
12
+
13
+ Metrics/PerceivedComplexity:
14
+ Exclude:
15
+ - "lib/k_domain/domain_model/transform_steps/*.rb"
16
+ - "lib/k_domain/domain_model/dtos/entity.rb"
17
+
18
+ Metrics/AbcSize:
19
+ Exclude:
20
+ - "lib/k_domain/domain_model/transform_steps/*.rb"
21
+ - "lib/k_domain/domain_model/dtos/rails_model.rb"
22
+ - "lib/k_domain/domain_model/dtos/entity.rb"
23
+ - "lib/k_domain/domain_model/dtos/column_old.rb"
24
+
25
+ Metrics/CyclomaticComplexity:
26
+ Exclude:
27
+ - "lib/k_domain/domain_model/transform_steps/*.rb"
28
+ - "lib/k_domain/domain_model/dtos/entity.rb"
10
29
 
11
30
  Metrics/BlockLength:
12
31
  Exclude:
@@ -34,12 +53,17 @@ Metrics/BlockLength:
34
53
 
35
54
  Metrics/MethodLength:
36
55
  Max: 25
56
+ Exclude:
57
+ - "lib/k_domain/domain_model/transform_steps/*.rb"
58
+ - "lib/k_domain/domain_model/dtos/rails_model.rb"
37
59
 
38
60
  Layout/LineLength:
39
61
  Max: 200
40
62
  # Ignores annotate output
41
63
  IgnoredPatterns: ['\A# \*\*']
42
64
  IgnoreCopDirectives: true
65
+ Exclude:
66
+ - "lib/k_domain/domain_model/transform_steps/*.rb"
43
67
 
44
68
  Lint/UnusedMethodArgument:
45
69
  AllowUnusedKeywordArguments: true
@@ -77,6 +101,12 @@ Lint/AmbiguousBlockAssociation:
77
101
  Style/AccessorGrouping:
78
102
  Enabled: false
79
103
 
104
+ Style/FormatStringToken:
105
+ Enabled: false
106
+
107
+ Style/Documentation:
108
+ Enabled: false
109
+
80
110
  Layout/SpaceBeforeComma:
81
111
  Enabled: false
82
112
  # My Preferences - End
data/STORIES.md CHANGED
@@ -8,9 +8,13 @@ As an Application Developer, I need a rich and configurable ERD schema, so I can
8
8
 
9
9
  ### Stories next on list
10
10
 
11
- As a Developer, I can DO_SOMETHING, so that I QUALITY_OF_LIFE
11
+ As a Developer, I can print any of the domain structures, so that I can visually my domain
12
12
 
13
- - Subtask
13
+ - Hook up log.structure
14
+
15
+ As a Developer, I can customize domain configuration, so that I can have opinions about names and types
16
+
17
+ - Handle traits
14
18
 
15
19
  ## Stories and tasks
16
20
 
data/k_domain.gemspec CHANGED
@@ -38,5 +38,7 @@ Gem::Specification.new do |spec|
38
38
  spec.require_paths = ['lib']
39
39
  # spec.extensions = ['ext/k_domain/extconf.rb']
40
40
 
41
+ spec.add_dependency 'activesupport' , '~> 6'
42
+ spec.add_dependency 'dry-struct', '~> 1'
41
43
  spec.add_dependency 'k_log' , '~> 0.0.0'
42
44
  end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ # log.warn 'models->domain' if AppDebug.require?
4
+
5
+ require_relative './dictionary/dictionary'
6
+ require_relative './investigate/issue'
7
+ require_relative './investigate/investigate'
8
+ require_relative './models/column'
9
+ require_relative './models/model'
10
+ require_relative './domain'
11
+ require_relative './schema'
12
+
13
+ # require_relative './helper/domain_config'
14
+ # require_relative './helper/main_key'
15
+ # require_relative './helper/traits'
16
+
17
+ # require_relative './belongs_to'
18
+ # require_relative './domain_statistics'
19
+ # # require_relative './domain_mapper'
20
+ # require_relative './entity'
21
+ # require_relative './entity_statistics'
22
+ # require_relative './foreign_key'
23
+ # require_relative './has_and_belongs_to_many'
24
+ # require_relative './has_many'
25
+ # require_relative './has_one'
26
+ # require_relative './name_options'
27
+ # require_relative './rails_model'
28
+ # require_relative './related_entity'
29
+ # require_relative './statistics'
30
+ # require_relative './validate'
31
+ # require_relative './validates'
32
+
33
+ module KDomain
34
+ module DomainModel
35
+ RUBY_TYPE = {
36
+ text: 'String',
37
+ string: 'String',
38
+ primary_key: 'Integer', # this could be GUID in future
39
+ foreign_key: 'Integer', # this could be GUID in future
40
+ integer: 'Integer',
41
+ bigint: 'Integer',
42
+ bigserial: 'Integer',
43
+ boolean: 'Boolean',
44
+ float: 'Float',
45
+ decimal: 'Decimal',
46
+ datetime: 'DateTime',
47
+ date: 'DateTime',
48
+ json: 'Hash',
49
+ jsonb: 'Hash',
50
+ hstore: 'Hash'
51
+ }.freeze
52
+
53
+ CSHARP_TYPE = {
54
+ string: 'string',
55
+ text: 'string', # NEED TO DEAL WITH THIS BETTER
56
+ integer: 'int',
57
+ bigint: 'int',
58
+ bigserial: 'long',
59
+ boolean: 'bool',
60
+ decimal: 'decimal',
61
+ float: 'double',
62
+ datetime: 'DateTime',
63
+ date: 'DateTime',
64
+ json: 'object',
65
+ jsonb: 'object',
66
+ hstore: 'object'
67
+ }.freeze
68
+
69
+ # this is used by the ruby migration files
70
+ DB_TYPE = {
71
+ boolean: 'boolean',
72
+ primary_key: 'integer',
73
+ foreign_key: 'integer',
74
+ integer: 'integer',
75
+ bigint: 'integer',
76
+ bigserial: 'bigserial',
77
+ decimal: 'decimal',
78
+ float: 'float',
79
+ datetime: 'datetime',
80
+ date: 'date',
81
+ text: 'text',
82
+ string: 'string',
83
+ json: 'json',
84
+ jsonb: 'jsonb',
85
+ hstore: 'hstore'
86
+ }.freeze
87
+ end
88
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class BelongsTo
6
+ KEYS = %i[a_lambda polymorphic class_name foreign_key primary_key inverse_of with_deleted code_duplicate].freeze
7
+
8
+ attr_accessor :name
9
+
10
+ attr_accessor :model_name
11
+ attr_accessor :model_name_plural
12
+
13
+ attr_accessor :a_lambda
14
+ attr_accessor :polymorphic
15
+ attr_accessor :class_name
16
+ attr_accessor :foreign_key
17
+ attr_accessor :primary_key
18
+ attr_accessor :inverse_of
19
+ attr_accessor :with_deleted
20
+
21
+ attr_accessor :related_entity
22
+ attr_accessor :code_duplicate
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDomain
4
+ module DomainModel
5
+ class ColumnOld
6
+ # DONE
7
+ RUBY_TYPE = {
8
+ string: 'String',
9
+ text: 'String',
10
+ primary_key: 'Integer', # this could be GUID in future
11
+ foreign_key: 'Integer', # this could be GUID in future
12
+ integer: 'Integer',
13
+ boolean: 'Boolean',
14
+ float: 'Float',
15
+ decimal: 'Decimal',
16
+ datetime: 'DateTime',
17
+ date: 'DateTime',
18
+ json: 'Hash',
19
+ jsonb: 'Hash',
20
+ hstore: 'Hash'
21
+ }.freeze
22
+
23
+ # DONE
24
+ CSHARP_TYPE = {
25
+ string: 'string',
26
+ text: 'string', # NEED TO DEAL WITH THIS BETTER
27
+ integer: 'int',
28
+ boolean: 'bool',
29
+ decimal: 'decimal',
30
+ float: 'double',
31
+ datetime: 'DateTime',
32
+ date: 'DateTime',
33
+ json: 'object',
34
+ jsonb: 'object',
35
+ hstore: 'object'
36
+ }.freeze
37
+
38
+ # this is used by the ruby migration files
39
+ # DONE
40
+ DB_TYPE = {
41
+ boolean: 'boolean',
42
+ primary_key: 'integer',
43
+ foreign_key: 'integer',
44
+ integer: 'integer',
45
+ decimal: 'decimal',
46
+ float: 'float',
47
+ datetime: 'datetime',
48
+ date: 'date',
49
+ text: 'text',
50
+ string: 'string',
51
+ json: 'json',
52
+ jsonb: 'jsonb',
53
+ hstore: 'hstore'
54
+ }.freeze
55
+
56
+ SIMPLE_ATTRIBS = %i[
57
+ name
58
+ name_plural
59
+ type
60
+ structure_type
61
+ foreign_key?
62
+ foreign_table
63
+ foreign_id
64
+ ].freeze
65
+
66
+ DETAILED_ATTRIBS = SIMPLE_ATTRIBS + %i[
67
+ title
68
+ required
69
+ reference_type
70
+ db_type
71
+ ruby_type
72
+ csharp_type
73
+ format_type
74
+ description
75
+ belongs_to
76
+ ]
77
+
78
+ EXTRA_ATTRIBS = DETAILED_ATTRIBS + %i[
79
+ precision
80
+ scale
81
+ default
82
+ null
83
+ limit
84
+ array
85
+ ]
86
+
87
+ # Name of the column
88
+ attr_accessor :name
89
+
90
+ # Name of the column in plural form
91
+ attr_accessor :name_plural
92
+
93
+ attr_accessor :type
94
+
95
+ # Human readable title
96
+ attr_accessor :title
97
+
98
+ # true
99
+ attr_accessor :required
100
+
101
+ attr_accessor :structure_type # :data, :foreign_key, :timestamp
102
+ attr_accessor :reference_type
103
+
104
+ # 'references' if foreign key, 'primary_key' if primary key, will map_from_type(type)) |
105
+ # attr_accessor :db_type
106
+
107
+ attr_accessor :format_type
108
+ attr_accessor :description
109
+
110
+ attr_accessor :foreign_key
111
+ alias foreign_key? foreign_key
112
+ attr_accessor :foreign_table
113
+ attr_accessor :belongs_to
114
+ # this may not always be accurate, should support override
115
+ attr_accessor :foreign_id
116
+ alias reference_table foreign_id
117
+
118
+ # Extra DB attributes
119
+ attr_accessor :precision
120
+ attr_accessor :scale
121
+ attr_accessor :default
122
+ attr_accessor :null
123
+ alias nullable null
124
+ attr_accessor :limit
125
+ attr_accessor :array
126
+
127
+ def format_default
128
+ return '' if default.nil?
129
+ return "\"#{default}\"" if default.is_a?(String)
130
+
131
+ # || default.is_a?(Symbol)
132
+ default.to_s
133
+ end
134
+
135
+ def format_null
136
+ null.nil? ? '' : null.to_s
137
+ end
138
+
139
+ def format_array
140
+ array.nil? ? '' : array.to_s
141
+ end
142
+
143
+ # DONE
144
+ def db_type
145
+ return @db_type if defined? @db_type
146
+
147
+ @db_type = DB_TYPE[type] || '******'
148
+ end
149
+
150
+ # DONE
151
+ def ruby_type
152
+ return @ruby_type if defined? @ruby_type
153
+
154
+ @ruby_type = RUBY_TYPE[type] || '******'
155
+ end
156
+
157
+ # DONE
158
+ def csharp_type
159
+ return @csharp_type if defined? @csharp_type
160
+
161
+ @csharp_type = CSHARP_TYPE[type] || '******'
162
+ end
163
+
164
+ def debug(*flags)
165
+ debug_simple if flags.include?(:simple)
166
+ debug_detailed if flags.include?(:detailed)
167
+ debug_extra if flags.include?(:extra)
168
+ end
169
+
170
+ private
171
+
172
+ def debug_simple
173
+ log.kv 'name' , name
174
+ log.kv 'name_plural' , name_plural
175
+ log.kv 'type' , type
176
+ log.kv 'structure_type' , structure_type
177
+ end
178
+
179
+ def debug_detailed
180
+ debug_simple
181
+ log.kv 'title' , title
182
+ log.kv 'required' , required
183
+ log.kv 'reference_type' , reference_type
184
+ log.kv 'db_type' , db_type
185
+ log.kv 'ruby_type' , ruby_type
186
+ log.kv 'csharp_type' , csharp_type
187
+ log.kv 'format_type' , format_type
188
+ log.kv 'description' , description
189
+
190
+ log.kv 'foreign_key?' , foreign_key?
191
+ log.kv 'foreign_table' , foreign_table
192
+ log.kv 'belongs_to' , belongs_to
193
+ log.kv 'foreign_id' , foreign_id
194
+ end
195
+
196
+ def debug_extra
197
+ debug_detailed
198
+
199
+ log.kv 'precision' , precision
200
+ log.kv 'scale' , scale
201
+ log.kv 'default' , default
202
+ log.kv 'null' , null
203
+ log.kv 'limit' , limit
204
+ log.kv 'array' , array
205
+ end
206
+ end
207
+
208
+ # ---------------------------------------------
209
+ # Available column keys that can be mapped from
210
+ # ---------------------------------------------
211
+ # name
212
+ # name_plural
213
+ # type
214
+ # foreign_key?
215
+ # foreign_table
216
+ # structure_type
217
+ # precision
218
+ # scale
219
+ # default
220
+ # null
221
+ # limit
222
+ # array
223
+ # belongs_to
224
+ end
225
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Domain class holds a dictionary entry
4
+ module KDomain
5
+ module DomainModel
6
+ class Dictionary < Dry::Struct
7
+ attribute :name , Types::Strict::String
8
+ attribute :type , Types::Strict::String
9
+ attribute :label , Types::Strict::String
10
+ attribute :segment , Types::Strict::String
11
+ attribute :models , Types::Strict::Array
12
+ attribute :model_count , Types::Strict::Integer
13
+ attribute :types , Types::Strict::Array
14
+ attribute :type_count , Types::Strict::Integer
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Domain class holds a list of the entities
4
+ module KDomain
5
+ module DomainModel
6
+ class Domain < Dry::Struct
7
+ attribute :models , Types::Strict::Array.of(KDomain::DomainModel::Model)
8
+ attribute :dictionary , Types::Strict::Array.of(KDomain::DomainModel::Dictionary)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Rails model represents information that is found the model.rb class in the rails project
4
+ module KDomain
5
+ module DomainModel
6
+ class DomainStatistics
7
+ attr_reader :domain
8
+ attr_accessor :column_counts
9
+ attr_accessor :code_counts
10
+ attr_accessor :code_dsl_counts
11
+ attr_accessor :data_counts
12
+ attr_accessor :issues
13
+
14
+ def initialize(domain)
15
+ @domain = domain
16
+ # @column_counts = OpenStruct.new(meta[:column_counts])
17
+ # @code_counts = OpenStruct.new(meta[:code_counts])
18
+ # @code_dsl_counts = OpenStruct.new(meta[:code_dsl_counts])
19
+ # @data_counts = OpenStruct.new(meta[:data_counts])
20
+ # @issues = meta[:issues]
21
+ end
22
+
23
+ def print
24
+ log.warn('Statistics ::')
25
+ log.kv('Database Entities', domain.entities.length)
26
+ end
27
+ end
28
+ end
29
+ end