k_domain 0.0.2 → 0.0.5
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 +31 -1
- data/STORIES.md +6 -2
- data/k_domain.gemspec +2 -0
- data/lib/k_domain/domain_model/dtos/_.rb +88 -0
- data/lib/k_domain/domain_model/dtos/belongs_to.rb +25 -0
- data/lib/k_domain/domain_model/dtos/column_old.rb +225 -0
- data/lib/k_domain/domain_model/dtos/dictionary/dictionary.rb +17 -0
- data/lib/k_domain/domain_model/dtos/domain.rb +11 -0
- data/lib/k_domain/domain_model/dtos/domain_statistics.rb +29 -0
- data/lib/k_domain/domain_model/dtos/entity.rb +338 -0
- data/lib/k_domain/domain_model/dtos/entity_statistics.rb +22 -0
- data/lib/k_domain/domain_model/dtos/foreign_key.rb +17 -0
- data/lib/k_domain/domain_model/dtos/has_and_belongs_to_many.rb +20 -0
- data/lib/k_domain/domain_model/dtos/has_many.rb +27 -0
- data/lib/k_domain/domain_model/dtos/has_one.rb +41 -0
- data/lib/k_domain/domain_model/dtos/investigate/investigate.rb +10 -0
- data/lib/k_domain/domain_model/dtos/investigate/issue.rb +13 -0
- data/lib/k_domain/domain_model/dtos/models/column.rb +49 -0
- data/lib/k_domain/domain_model/dtos/models/model.rb +111 -0
- data/lib/k_domain/domain_model/dtos/name_options.rb +10 -0
- data/lib/k_domain/domain_model/dtos/rails_controller.rb +10 -0
- data/lib/k_domain/domain_model/dtos/rails_model.rb +92 -0
- data/lib/k_domain/domain_model/dtos/related_entity.rb +36 -0
- data/lib/k_domain/domain_model/dtos/schema.rb +12 -0
- data/lib/k_domain/domain_model/dtos/statistics.rb +21 -0
- data/lib/k_domain/domain_model/dtos/validate.rb +25 -0
- data/lib/k_domain/domain_model/dtos/validates.rb +50 -0
- data/lib/k_domain/domain_model/load.rb +29 -0
- data/lib/k_domain/domain_model/transform.rb +94 -0
- data/lib/k_domain/domain_model/transform_steps/_.rb +9 -0
- data/lib/k_domain/domain_model/transform_steps/step.rb +123 -0
- data/lib/k_domain/domain_model/transform_steps/step1_attach_db_schema.rb +21 -0
- data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +62 -0
- data/lib/k_domain/domain_model/transform_steps/step3_attach_columns.rb +137 -0
- data/lib/k_domain/domain_model/transform_steps/step4_attach_erd_files.rb +454 -0
- data/lib/k_domain/domain_model/transform_steps/step5_attach_dictionary.rb +56 -0
- data/lib/k_domain/raw_db_schema/dtos/_.rb +14 -0
- data/lib/k_domain/raw_db_schema/dtos/column.rb +16 -0
- data/lib/k_domain/raw_db_schema/dtos/database.rb +11 -0
- data/lib/k_domain/raw_db_schema/dtos/foreign_key.rb +14 -0
- data/lib/k_domain/raw_db_schema/dtos/index.rb +14 -0
- data/lib/k_domain/raw_db_schema/dtos/schema.rb +18 -0
- data/lib/k_domain/raw_db_schema/dtos/table.rb +21 -0
- data/lib/k_domain/raw_db_schema/dtos/unique_key.rb +14 -0
- data/lib/k_domain/raw_db_schema/load.rb +29 -0
- data/lib/k_domain/{raw_schema → raw_db_schema}/template.rb +0 -0
- data/lib/k_domain/{raw_schema → raw_db_schema}/transform.rb +37 -21
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +14 -1
- metadata +74 -4
@@ -0,0 +1,338 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module DomainModel
|
5
|
+
class Entity
|
6
|
+
# Name of the entity model
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
# Name of the entity model in plural form
|
10
|
+
attr_accessor :name_plural
|
11
|
+
|
12
|
+
# @param [Symbol] value The value of ID has different meanings
|
13
|
+
# @option value :true Id column exists and it uses an Integer type
|
14
|
+
# @option value :false Id column does not exist
|
15
|
+
# @option value :bigserial Id column exists and it uses a BigSerial type
|
16
|
+
attr_accessor :id
|
17
|
+
|
18
|
+
# Currently only has the value :cascade
|
19
|
+
attr_accessor :force
|
20
|
+
|
21
|
+
# Model columns
|
22
|
+
attr_accessor :columns
|
23
|
+
|
24
|
+
# Model relationships - one_to_one, one_to_many and many_to_many
|
25
|
+
attr_accessor :relations_one_to_one
|
26
|
+
|
27
|
+
# This entity has a main field that is useful for rendering and may be used for unique constraint, may also be called display_name
|
28
|
+
attr_accessor :main_key
|
29
|
+
|
30
|
+
attr_accessor :trait1
|
31
|
+
attr_accessor :trait2
|
32
|
+
attr_accessor :trait3
|
33
|
+
|
34
|
+
# investigate
|
35
|
+
attr_accessor :td_query
|
36
|
+
|
37
|
+
# Model type - :entity, :basic_user, :admin_user
|
38
|
+
attr_accessor :model_type
|
39
|
+
|
40
|
+
attr_accessor :rails_model
|
41
|
+
attr_accessor :statistics
|
42
|
+
|
43
|
+
def key?
|
44
|
+
!main_key.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
def no_key
|
48
|
+
main_key.nil?
|
49
|
+
end
|
50
|
+
alias keyless? no_key
|
51
|
+
|
52
|
+
# Can probably deprecate model_
|
53
|
+
alias model_name name
|
54
|
+
alias names name_plural
|
55
|
+
|
56
|
+
alias td_key1 trait1
|
57
|
+
alias td_key2 trait2
|
58
|
+
alias td_key3 trait3
|
59
|
+
|
60
|
+
# alias :name :student_name # not wrong, only for getter
|
61
|
+
# alias :name= :student_name= # add this for setter
|
62
|
+
# alias :name? :student_name? # add this for boolean
|
63
|
+
|
64
|
+
attr_accessor :belongs_to
|
65
|
+
attr_accessor :has_one
|
66
|
+
attr_accessor :has_many
|
67
|
+
attr_accessor :has_and_belongs_to_many
|
68
|
+
|
69
|
+
# Needs to move into RailsModel
|
70
|
+
attr_accessor :validates
|
71
|
+
attr_accessor :validate
|
72
|
+
|
73
|
+
def relations?
|
74
|
+
# log.kv 'has_one', has_one.length
|
75
|
+
# log.kv 'has_many', has_many.length
|
76
|
+
# log.kv 'has_and_belongs_to_many', has_and_belongs_to_many.length
|
77
|
+
has_one.length.positive? || has_many.length.positive? || has_and_belongs_to_many.length.positive?
|
78
|
+
end
|
79
|
+
|
80
|
+
def initialize
|
81
|
+
@columns = []
|
82
|
+
@relations = []
|
83
|
+
|
84
|
+
@belongs_to = []
|
85
|
+
@has_one = []
|
86
|
+
@has_many = []
|
87
|
+
@has_and_belongs_to_many = []
|
88
|
+
|
89
|
+
@rails_model = nil
|
90
|
+
@statistics = nil
|
91
|
+
end
|
92
|
+
|
93
|
+
# Filter helpers
|
94
|
+
def filter_columns(type_of_columns)
|
95
|
+
case type_of_columns
|
96
|
+
when :columns_data
|
97
|
+
columns_data
|
98
|
+
when :columns_data_optional
|
99
|
+
columns_data_optional
|
100
|
+
when :columns_data_required
|
101
|
+
columns_data_required
|
102
|
+
when :columns_data_foreign
|
103
|
+
columns_data_foreign
|
104
|
+
when :columns_primary
|
105
|
+
columns_primary
|
106
|
+
when :columns_foreign
|
107
|
+
columns_foreign
|
108
|
+
when :columns_virtual
|
109
|
+
columns_virtual
|
110
|
+
when :columns_data_foreign_virtual
|
111
|
+
columns_data_foreign_virtual
|
112
|
+
when :columns_data_primary
|
113
|
+
columns_data_primary
|
114
|
+
when :columns_data_virtual
|
115
|
+
columns_data_virtual
|
116
|
+
else
|
117
|
+
columns
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_h
|
122
|
+
{
|
123
|
+
name: name,
|
124
|
+
name_plural: name_plural,
|
125
|
+
type: type,
|
126
|
+
title: title,
|
127
|
+
required: required,
|
128
|
+
structure_type: structure_type,
|
129
|
+
reference_type: reference_type,
|
130
|
+
format_type: format_type,
|
131
|
+
description: description,
|
132
|
+
foreign_key: foreign_key,
|
133
|
+
foreign_table: foreign_table,
|
134
|
+
belongs_to: belongs_to,
|
135
|
+
foreign_id: foreign_id,
|
136
|
+
precision: precision,
|
137
|
+
scale: scale,
|
138
|
+
default: default,
|
139
|
+
null: null,
|
140
|
+
limit: limit,
|
141
|
+
array: array
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
# DONE
|
146
|
+
def columns_data
|
147
|
+
@columns_data ||= columns_for_structure_types(:data)
|
148
|
+
end
|
149
|
+
alias rows_fields columns_data
|
150
|
+
|
151
|
+
# TODO
|
152
|
+
def columns_data_optional
|
153
|
+
@columns_data_optional ||= columns_for_structure_types(:data).select { |_c| true }
|
154
|
+
end
|
155
|
+
|
156
|
+
# TODO
|
157
|
+
def columns_data_required
|
158
|
+
@columns_data_required ||= columns_for_structure_types(:data).select { |_c| false }
|
159
|
+
end
|
160
|
+
|
161
|
+
# DONE
|
162
|
+
def columns_primary
|
163
|
+
@columns_primary ||= columns_for_structure_types(:primary_key)
|
164
|
+
end
|
165
|
+
|
166
|
+
# DONE
|
167
|
+
def columns_foreign
|
168
|
+
@columns_foreign ||= columns_for_structure_types(:foreign_key)
|
169
|
+
end
|
170
|
+
|
171
|
+
# DONE
|
172
|
+
def columns_timestamp
|
173
|
+
@columns_data_timestamp ||= columns_for_structure_types(:timestamp)
|
174
|
+
end
|
175
|
+
|
176
|
+
# DONE
|
177
|
+
def columns_deleted_at
|
178
|
+
@columns_data_deleted_at ||= columns_for_structure_types(:deleted_at)
|
179
|
+
end
|
180
|
+
|
181
|
+
# DONE
|
182
|
+
def columns_virtual
|
183
|
+
@columns_virtual ||= columns_for_structure_types(:timestamp, :deleted_at)
|
184
|
+
end
|
185
|
+
|
186
|
+
# DONE
|
187
|
+
def columns_data_foreign
|
188
|
+
@columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key)
|
189
|
+
end
|
190
|
+
alias rows_fields_and_fk columns_data_foreign
|
191
|
+
|
192
|
+
# DONE
|
193
|
+
def columns_data_primary
|
194
|
+
@columns_data_primary ||= columns_for_structure_types(:data, :primary_key)
|
195
|
+
end
|
196
|
+
alias rows_fields_and_pk columns_data_primary
|
197
|
+
|
198
|
+
# DONE
|
199
|
+
def columns_data_virtual
|
200
|
+
@columns_data_virtual ||= columns_for_structure_types(:data, :timestamp, :deleted_at)
|
201
|
+
end
|
202
|
+
alias rows_fields_and_virtual columns_data_virtual
|
203
|
+
|
204
|
+
# DONE
|
205
|
+
def columns_data_foreign_virtual
|
206
|
+
@columns_data_foreign_virtual ||= columns_for_structure_types(:data, :foreign_key, :timestamp, :deleted_at)
|
207
|
+
end
|
208
|
+
|
209
|
+
# DONE
|
210
|
+
def columns_for_structure_types(*structure_types)
|
211
|
+
columns.select { |column| structure_types.include?(column.structure_type) }
|
212
|
+
end
|
213
|
+
|
214
|
+
# Debug helpers
|
215
|
+
|
216
|
+
def debug(*flags)
|
217
|
+
debug_simple if flags.include?(:simple)
|
218
|
+
debug_detailed if flags.include?(:detailed)
|
219
|
+
debug_extra if flags.include?(:extra)
|
220
|
+
|
221
|
+
debug_columns(*flags)
|
222
|
+
debug_belongs_to(*flags)
|
223
|
+
debug_has_one(*flags)
|
224
|
+
debug_has_many(*flags)
|
225
|
+
debug_has_and_belongs_to_many(*flags)
|
226
|
+
# log.kv 'relations' , relations
|
227
|
+
end
|
228
|
+
|
229
|
+
def debug_simple
|
230
|
+
log.kv 'name' , name
|
231
|
+
log.kv 'name_plural' , name_plural
|
232
|
+
log.kv 'main_key' , main_key
|
233
|
+
log.kv 'model_type' , model_type
|
234
|
+
end
|
235
|
+
|
236
|
+
def debug_detailed
|
237
|
+
debug_simple
|
238
|
+
log.kv 'id' , id
|
239
|
+
log.kv 'trait1' , trait1
|
240
|
+
log.kv 'trait2' , trait2
|
241
|
+
log.kv 'trait3' , trait3
|
242
|
+
log.kv 'td_query' , td_query
|
243
|
+
log.kv 'key?' , key?
|
244
|
+
log.kv 'no_key' , no_key
|
245
|
+
end
|
246
|
+
|
247
|
+
def debug_extra
|
248
|
+
debug_detailed
|
249
|
+
log.kv 'force' , force
|
250
|
+
end
|
251
|
+
|
252
|
+
def debug_columns(*flags, column_list: columns)
|
253
|
+
c_simple = flags.include?(:columns_simple)
|
254
|
+
c_detailed = flags.include?(:columns_detailed)
|
255
|
+
c_extra = flags.include?(:columns_extra)
|
256
|
+
c_tabular = flags.include?(:columns_tabular_simple) || flags.include?(:columns_tabular)
|
257
|
+
c_tabular_detailed = flags.include?(:columns_tabular_detailed)
|
258
|
+
c_tabular_extra = flags.include?(:columns_tabular_extra)
|
259
|
+
|
260
|
+
return unless c_simple || c_detailed || c_extra || c_tabular || c_tabular_detailed || c_tabular_extra
|
261
|
+
|
262
|
+
log.section_heading('columns')
|
263
|
+
|
264
|
+
column_list.each { |column| column.debug(:simple) } if c_simple
|
265
|
+
column_list.each { |column| column.debug(:detailed) } if c_detailed
|
266
|
+
column_list.each { |column| column.debug(:extra) } if c_extra
|
267
|
+
tp column_list, *Column::SIMPLE_ATTRIBS if c_tabular
|
268
|
+
tp column_list, *Column::DETAILED_ATTRIBS if c_tabular_detailed
|
269
|
+
tp column_list, *Column::EXTRA_ATTRIBS if c_tabular_extra
|
270
|
+
end
|
271
|
+
|
272
|
+
def debug_belongs_to(*flags)
|
273
|
+
c_simple = flags.include?(:belongs_to_tabular)
|
274
|
+
|
275
|
+
return unless c_simple && belongs_to.length.positive?
|
276
|
+
|
277
|
+
log.section_heading('belongs_to')
|
278
|
+
|
279
|
+
tp belongs_to, :name, :model_name, :model_name_plural, *BelongsTo::KEYS
|
280
|
+
end
|
281
|
+
|
282
|
+
def debug_has_one(*flags)
|
283
|
+
c_simple = flags.include?(:has_one_tabular)
|
284
|
+
|
285
|
+
return unless c_simple && has_one.length.positive?
|
286
|
+
|
287
|
+
log.section_heading('has_one')
|
288
|
+
|
289
|
+
tp has_one, :name, :model_name, :model_name_plural, *HasOne::KEYS
|
290
|
+
end
|
291
|
+
|
292
|
+
def debug_has_many(*flags)
|
293
|
+
c_simple = flags.include?(:has_many_tabular)
|
294
|
+
|
295
|
+
return unless c_simple && has_many.length.positive?
|
296
|
+
|
297
|
+
log.section_heading('has_many')
|
298
|
+
|
299
|
+
tp has_many, :name, :model_name, :model_name_plural, *HasMany::KEYS
|
300
|
+
end
|
301
|
+
|
302
|
+
def debug_has_and_belongs_to_many(*flags)
|
303
|
+
c_simple = flags.include?(:has_and_belongs_to_many_tabular)
|
304
|
+
|
305
|
+
return unless c_simple && has_and_belongs_to_many.length.positive?
|
306
|
+
|
307
|
+
log.section_heading('has_and_belongs_to_many')
|
308
|
+
|
309
|
+
tp has_and_belongs_to_many, :name, :model_name, :model_name_plural, *HasAndBelongsToMany::KEYS
|
310
|
+
end
|
311
|
+
end
|
312
|
+
# ---------------------------------------------
|
313
|
+
# Available entity keys that can be mapped from
|
314
|
+
# ---------------------------------------------
|
315
|
+
# name
|
316
|
+
# name_plural
|
317
|
+
# id
|
318
|
+
# force
|
319
|
+
# created
|
320
|
+
# updated
|
321
|
+
# columns
|
322
|
+
# data_columns
|
323
|
+
# foreign_columns
|
324
|
+
# belongs
|
325
|
+
# has_one
|
326
|
+
# has_many
|
327
|
+
# has_and_belongs_to_many
|
328
|
+
# class_methods
|
329
|
+
# public_class_methods
|
330
|
+
# private_class_methods
|
331
|
+
# instance_methods
|
332
|
+
# public_instance_methods
|
333
|
+
# private_instance_methods
|
334
|
+
# default_scope
|
335
|
+
# scopes
|
336
|
+
# meta
|
337
|
+
end
|
338
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 EntityStatistics
|
7
|
+
attr_accessor :column_counts
|
8
|
+
attr_accessor :code_counts
|
9
|
+
attr_accessor :code_dsl_counts
|
10
|
+
attr_accessor :data_counts
|
11
|
+
attr_accessor :issues
|
12
|
+
|
13
|
+
def initialize(entity)
|
14
|
+
# @column_counts = OpenStruct.new(meta[:column_counts])
|
15
|
+
# @code_counts = OpenStruct.new(meta[:code_counts])
|
16
|
+
# @code_dsl_counts = OpenStruct.new(meta[:code_dsl_counts])
|
17
|
+
# @data_counts = OpenStruct.new(meta[:data_counts])
|
18
|
+
# @issues = meta[:issues]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module DomainModel
|
5
|
+
class ForeignKey
|
6
|
+
KEYS = %i[column name on_update on_delete].freeze
|
7
|
+
|
8
|
+
attr_accessor :left
|
9
|
+
attr_accessor :right
|
10
|
+
|
11
|
+
attr_accessor :column
|
12
|
+
attr_accessor :name
|
13
|
+
attr_accessor :on_update
|
14
|
+
attr_accessor :on_delete
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module DomainModel
|
5
|
+
class HasAndBelongsToMany
|
6
|
+
KEYS = %i[a_lambda autosave 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 :autosave
|
15
|
+
|
16
|
+
attr_accessor :related_entity
|
17
|
+
attr_accessor :code_duplicate
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module DomainModel
|
5
|
+
class HasMany
|
6
|
+
KEYS = %i[a_lambda as dependent through class_name inverse_of primary_key foreign_key source 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 :as
|
15
|
+
attr_accessor :dependent
|
16
|
+
attr_accessor :through
|
17
|
+
attr_accessor :class_name
|
18
|
+
attr_accessor :inverse_of
|
19
|
+
attr_accessor :primary_key
|
20
|
+
attr_accessor :foreign_key
|
21
|
+
attr_accessor :source
|
22
|
+
|
23
|
+
attr_accessor :related_entity
|
24
|
+
attr_accessor :code_duplicate
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module DomainModel
|
5
|
+
class HasOne
|
6
|
+
# KEYS = [:model_name, :model_name_plural, :a_lambda, :class_name, :foreign_key, :primary_key, :infer_key]
|
7
|
+
KEYS = %i[a_lambda class_name foreign_key primary_key infer_key code_duplicate].freeze
|
8
|
+
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
attr_accessor :model_name
|
12
|
+
attr_accessor :model_name_plural
|
13
|
+
|
14
|
+
attr_accessor :a_lambda
|
15
|
+
attr_accessor :class_name
|
16
|
+
attr_accessor :foreign_key
|
17
|
+
attr_accessor :primary_key
|
18
|
+
|
19
|
+
def infer_key
|
20
|
+
primary_key.nil? ? "#{name}_id" : primary_key
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :related_entity
|
24
|
+
attr_accessor :code_duplicate
|
25
|
+
|
26
|
+
def to_h
|
27
|
+
{
|
28
|
+
name: name,
|
29
|
+
model_name: model_name,
|
30
|
+
model_name_plural: model_name_plural,
|
31
|
+
a_lambda: a_lambda,
|
32
|
+
class_name: class_name,
|
33
|
+
foreign_key: foreign_key,
|
34
|
+
primary_key: primary_key,
|
35
|
+
code_duplicate: code_duplicate,
|
36
|
+
related_entity: related_entity.to_h
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain class holds an investigation entry
|
4
|
+
module KDomain
|
5
|
+
module DomainModel
|
6
|
+
class Issue < Dry::Struct
|
7
|
+
attribute :step , Types::Strict::String
|
8
|
+
attribute :location , Types::Strict::String
|
9
|
+
attribute :key , Types::Strict::String.optional.default(nil)
|
10
|
+
attribute :message , Types::Strict::String
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KDomain
|
4
|
+
module DomainModel
|
5
|
+
class Column < Dry::Struct
|
6
|
+
attribute :name , Types::Strict::String # "source_account_id"
|
7
|
+
attribute :name_plural , Types::Strict::String # "source_account_ids"
|
8
|
+
attribute :type , Types::Coercible::Symbol # "integer"
|
9
|
+
attribute :precision , Types::Strict::Integer.optional.default(nil) # null
|
10
|
+
attribute :scale , Types::Strict::Integer.optional.default(nil) # null
|
11
|
+
attribute :default , Types::Nominal::Any.optional.default(nil) # null
|
12
|
+
attribute :null , Types::Nominal::Any.optional.default(nil) # null
|
13
|
+
attribute :limit , Types::Strict::Integer.optional.default(nil) # null
|
14
|
+
attribute :array , Types::Strict::Bool.optional.default(nil) # null
|
15
|
+
|
16
|
+
# Calculated value
|
17
|
+
attribute :structure_type , Types::Coercible::Symbol #
|
18
|
+
attribute :foreign_key , Types::Strict::Bool.optional.default(nil) #
|
19
|
+
attribute :foreign_table , Types::Strict::String #
|
20
|
+
attribute :foreign_table_plural , Types::Strict::String #
|
21
|
+
|
22
|
+
# def data_column
|
23
|
+
# @columns_data ||= structure_type?(:data)
|
24
|
+
# end
|
25
|
+
|
26
|
+
# def structure_type?(*structure_types)
|
27
|
+
# structure_types.include?(column.structure_type)
|
28
|
+
# end
|
29
|
+
|
30
|
+
def db_type
|
31
|
+
return @db_type if defined? @db_type
|
32
|
+
|
33
|
+
@db_type = DB_TYPE[type] || '******'
|
34
|
+
end
|
35
|
+
|
36
|
+
def ruby_type
|
37
|
+
return @ruby_type if defined? @ruby_type
|
38
|
+
|
39
|
+
@ruby_type = RUBY_TYPE[type] || '******'
|
40
|
+
end
|
41
|
+
|
42
|
+
def csharp_type
|
43
|
+
return @csharp_type if defined? @csharp_type
|
44
|
+
|
45
|
+
@csharp_type = CSHARP_TYPE[type] || '******'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain class holds a list of the entities
|
4
|
+
module KDomain
|
5
|
+
module DomainModel
|
6
|
+
class Model < Dry::Struct
|
7
|
+
class Pk < Dry::Struct
|
8
|
+
attribute :name , Types::Strict::String.optional.default(nil)
|
9
|
+
attribute :type , Types::Strict::String.optional.default(nil)
|
10
|
+
attribute :exist , Types::Strict::Bool
|
11
|
+
end
|
12
|
+
|
13
|
+
class ErdLocation < Dry::Struct
|
14
|
+
attribute :file , Types::Strict::String
|
15
|
+
attribute :exist , Types::Strict::Bool
|
16
|
+
attribute :state , Types::Strict::Array
|
17
|
+
end
|
18
|
+
|
19
|
+
attribute :name , Types::Strict::String
|
20
|
+
attribute :name_plural , Types::Strict::String
|
21
|
+
attribute :table_name , Types::Strict::String
|
22
|
+
# Model type - :entity, :basic_user, :admin_user, possibly: m2m, agg_root
|
23
|
+
attribute :type , Types::Strict::Symbol.optional.default(:entity)
|
24
|
+
attribute :pk , KDomain::DomainModel::Model::Pk
|
25
|
+
attribute :erd_location , KDomain::DomainModel::Model::ErdLocation
|
26
|
+
attribute :columns , Types::Strict::Array.of(KDomain::DomainModel::Column)
|
27
|
+
|
28
|
+
def ruby?
|
29
|
+
location.exist
|
30
|
+
end
|
31
|
+
|
32
|
+
def pk?
|
33
|
+
pk.exist
|
34
|
+
end
|
35
|
+
|
36
|
+
# If filled in, the model has a main field that is useful for rendering and may be used for unique constraint, may also be called display_name
|
37
|
+
def main_key
|
38
|
+
@main_key ||= MainKey.lookup(name, columns_data)
|
39
|
+
end
|
40
|
+
|
41
|
+
def traits
|
42
|
+
@traits ||= Traits.lookup(name)
|
43
|
+
end
|
44
|
+
|
45
|
+
# def where()
|
46
|
+
# end
|
47
|
+
|
48
|
+
# def columns_where()
|
49
|
+
# end
|
50
|
+
|
51
|
+
# Column filters
|
52
|
+
|
53
|
+
def columns_data
|
54
|
+
@columns_data ||= columns_for_structure_types(:data)
|
55
|
+
end
|
56
|
+
|
57
|
+
# def columns_data_optional
|
58
|
+
# @columns_data_optional ||= columns_for_structure_types(:data).select { |c| true }
|
59
|
+
# end
|
60
|
+
|
61
|
+
# def columns_data_required
|
62
|
+
# @columns_data_required ||= columns_for_structure_types(:data).select { |c| false }
|
63
|
+
# end
|
64
|
+
|
65
|
+
def columns_primary
|
66
|
+
@columns_primary ||= columns_for_structure_types(:primary_key)
|
67
|
+
end
|
68
|
+
|
69
|
+
def columns_foreign
|
70
|
+
@columns_foreign ||= columns_for_structure_types(:foreign_key)
|
71
|
+
end
|
72
|
+
|
73
|
+
def columns_timestamp
|
74
|
+
@columns_data_timestamp ||= columns_for_structure_types(:timestamp)
|
75
|
+
end
|
76
|
+
|
77
|
+
def columns_deleted_at
|
78
|
+
@columns_data_deleted_at ||= columns_for_structure_types(:deleted_at)
|
79
|
+
end
|
80
|
+
|
81
|
+
def columns_virtual
|
82
|
+
@columns_virtual ||= columns_for_structure_types(:timestamp, :deleted_at)
|
83
|
+
end
|
84
|
+
|
85
|
+
def columns_data_foreign
|
86
|
+
@columns_data_foreign ||= columns_for_structure_types(:data, :foreign_key)
|
87
|
+
end
|
88
|
+
alias rows_fields_and_fk columns_data_foreign
|
89
|
+
|
90
|
+
def columns_data_primary
|
91
|
+
@columns_data_primary ||= columns_for_structure_types(:data, :primary_key)
|
92
|
+
end
|
93
|
+
alias rows_fields_and_pk columns_data_primary
|
94
|
+
|
95
|
+
def columns_data_virtual
|
96
|
+
@columns_data_virtual ||= columns_for_structure_types(:data, :timestamp, :deleted_at)
|
97
|
+
end
|
98
|
+
alias rows_fields_and_virtual columns_data_virtual
|
99
|
+
|
100
|
+
def columns_data_foreign_virtual
|
101
|
+
@columns_data_foreign_virtual ||= columns_for_structure_types(:data, :foreign_key, :timestamp, :deleted_at)
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def columns_for_structure_types(*structure_types)
|
107
|
+
columns.select { |column| structure_types.include?(column.structure_type) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|