dynamic_migrations 3.8.6 → 3.8.8
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/CHANGELOG.md +27 -0
- data/lib/dynamic_migrations/active_record/migrators/validation.rb +2 -20
- data/lib/dynamic_migrations/postgres/generator/enum.rb +13 -9
- data/lib/dynamic_migrations/postgres/generator/fragment.rb +10 -3
- data/lib/dynamic_migrations/postgres/generator/function.rb +13 -13
- data/lib/dynamic_migrations/postgres/generator/migration.rb +45 -7
- data/lib/dynamic_migrations/postgres/generator/table_migration.rb +2 -0
- data/lib/dynamic_migrations/postgres/generator/validation.rb +1 -3
- data/lib/dynamic_migrations/postgres/generator/validation_template_base.rb +1 -7
- data/lib/dynamic_migrations/postgres/generator.rb +100 -46
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rb +2 -2
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/enums.rb +10 -10
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/functions.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/columns.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/foreign_key_constraints.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/indexes.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/primary_key.rb +6 -6
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/triggers.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/unique_constraints.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables/validations.rb +11 -11
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables.rb +8 -8
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas.rb +3 -3
- data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations.rb +4 -4
- data/lib/dynamic_migrations/postgres/server/database/differences.rb +25 -20
- data/lib/dynamic_migrations/postgres/server/database/keys_and_unique_constraints_loader.rb +2 -2
- data/lib/dynamic_migrations/postgres/server/database/loaded_schemas_builder.rb +1 -1
- data/lib/dynamic_migrations/postgres/server/database/schema/enum.rb +9 -2
- data/lib/dynamic_migrations/postgres/server/database/schema/function.rb +2 -2
- data/lib/dynamic_migrations/postgres/server/database/schema/table/column.rb +6 -2
- data/lib/dynamic_migrations/postgres/server/database/schema/table/columns.rb +0 -6
- data/lib/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraint.rb +6 -2
- data/lib/dynamic_migrations/postgres/server/database/schema/table/index.rb +7 -3
- data/lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb +6 -2
- data/lib/dynamic_migrations/postgres/server/database/schema/table/trigger.rb +10 -8
- data/lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb +2 -2
- data/lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb +6 -2
- data/lib/dynamic_migrations/postgres/server/database/schema/table/validation.rb +12 -19
- data/lib/dynamic_migrations/postgres/server/database/schema/table.rb +62 -2
- data/lib/dynamic_migrations/postgres/server/database/validations_loader.rb +1 -3
- data/lib/dynamic_migrations/version.rb +1 -1
- data/sig/dynamic_migrations/active_record/migrators/validation.rbs +1 -1
- data/sig/dynamic_migrations/postgres/generator/enum.rbs +2 -0
- data/sig/dynamic_migrations/postgres/generator/fragment.rbs +3 -0
- data/sig/dynamic_migrations/postgres/generator/function.rbs +1 -0
- data/sig/dynamic_migrations/postgres/generator/migration.rbs +1 -0
- data/sig/dynamic_migrations/postgres/generator/schema_migration.rbs +2 -0
- data/sig/dynamic_migrations/postgres/generator/table_migration.rbs +3 -0
- data/sig/dynamic_migrations/postgres/generator/validation_template_base.rbs +0 -1
- data/sig/dynamic_migrations/postgres/generator.rbs +3 -1
- data/sig/dynamic_migrations/postgres/server/database/schema/enum.rbs +3 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/column.rbs +3 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraint.rbs +3 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/index.rbs +3 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/primary_key.rbs +3 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/trigger.rbs +3 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rbs +3 -0
- data/sig/dynamic_migrations/postgres/server/database/schema/table/validation.rbs +4 -3
- data/sig/dynamic_migrations/postgres/server/database/schema/table.rbs +3 -0
- metadata +2 -3
- data/lib/dynamic_migrations/name_helper.rb +0 -13
@@ -11,10 +11,10 @@ module DynamicMigrations
|
|
11
11
|
module Validations
|
12
12
|
def process_validations schema_name, table_name, configuration_validations, database_validations
|
13
13
|
# process all the validations
|
14
|
-
log.
|
14
|
+
log.debug " Processing Validations"
|
15
15
|
validation_names = (configuration_validations.keys + database_validations.keys).uniq
|
16
16
|
validation_names.each do |validation_name|
|
17
|
-
log.
|
17
|
+
log.debug " Processing Validation #{validation_name}"
|
18
18
|
process_validation schema_name, table_name, validation_name, configuration_validations[validation_name] || {}, database_validations[validation_name] || {}
|
19
19
|
end
|
20
20
|
end
|
@@ -23,7 +23,7 @@ module DynamicMigrations
|
|
23
23
|
# If the validation exists in the configuration but not in the database
|
24
24
|
# then we have to create it.
|
25
25
|
if configuration_validation[:exists] == true && !database_validation[:exists]
|
26
|
-
log.
|
26
|
+
log.debug " Validation `#{validation_name}` exists in configuration but not in the database"
|
27
27
|
|
28
28
|
# a migration to create the validation
|
29
29
|
validation = @database.configured_schema(schema_name).table(table_name).validation(validation_name)
|
@@ -32,7 +32,7 @@ module DynamicMigrations
|
|
32
32
|
# If the schema exists in the database but not in the configuration
|
33
33
|
# then we need to delete it.
|
34
34
|
elsif database_validation[:exists] == true && !configuration_validation[:exists]
|
35
|
-
log.
|
35
|
+
log.debug " Validation `#{validation_name}` exists in database but not in the configuration"
|
36
36
|
|
37
37
|
# a migration to create the validation
|
38
38
|
validation = @database.loaded_schema(schema_name).table(table_name).validation(validation_name)
|
@@ -42,9 +42,9 @@ module DynamicMigrations
|
|
42
42
|
# but the definition (except description, which is handled seeprately below) is different
|
43
43
|
# then we need to update the definition.
|
44
44
|
elsif configuration_validation.except(:exists, :description).filter { |name, attributes| attributes[:matches] == false }.any?
|
45
|
-
log.
|
45
|
+
log.debug " Validation `#{validation_name}` exists in both configuration and the database"
|
46
46
|
|
47
|
-
log.
|
47
|
+
log.debug " Validation `#{validation_name}` is different"
|
48
48
|
# recreate the validation
|
49
49
|
original_validation = @database.loaded_schema(schema_name).table(table_name).validation(validation_name)
|
50
50
|
updated_validation = @database.configured_schema(schema_name).table(table_name).validation(validation_name)
|
@@ -53,10 +53,10 @@ module DynamicMigrations
|
|
53
53
|
if configuration_validation[:description][:matches] == false
|
54
54
|
# if the description was removed
|
55
55
|
if configuration_validation[:description].nil?
|
56
|
-
log.
|
56
|
+
log.debug " Validation `#{validation_name}` description exists in database but not in the configuration"
|
57
57
|
@generator.remove_validation_comment updated_validation
|
58
58
|
else
|
59
|
-
log.
|
59
|
+
log.debug " Validation `#{validation_name}` does not match"
|
60
60
|
@generator.set_validation_comment updated_validation
|
61
61
|
end
|
62
62
|
end
|
@@ -64,15 +64,15 @@ module DynamicMigrations
|
|
64
64
|
# If the validation exists in both the configuration and database representations
|
65
65
|
# but the description is different then we need to update the description.
|
66
66
|
elsif configuration_validation[:description][:matches] == false
|
67
|
-
log.
|
67
|
+
log.debug " Validation `#{validation_name}` exists in both configuration and the database"
|
68
68
|
|
69
69
|
validation = @database.configured_schema(schema_name).table(table_name).validation(validation_name)
|
70
70
|
# if the description was removed
|
71
71
|
if configuration_validation[:description].nil?
|
72
|
-
log.
|
72
|
+
log.debug " Validation `#{validation_name}` description exists in database but not in the configuration"
|
73
73
|
@generator.remove_validation_comment validation
|
74
74
|
else
|
75
|
-
log.
|
75
|
+
log.debug " Validation `#{validation_name}` does not match"
|
76
76
|
@generator.set_validation_comment validation
|
77
77
|
end
|
78
78
|
end
|
data/lib/dynamic_migrations/postgres/server/database/differences/to_migrations/schemas/tables.rb
CHANGED
@@ -10,10 +10,10 @@ module DynamicMigrations
|
|
10
10
|
module Tables
|
11
11
|
def process_tables schema_name, configuration_tables, database_tables
|
12
12
|
# process all the tables
|
13
|
-
log.
|
13
|
+
log.debug " Processing Tables"
|
14
14
|
table_names = (configuration_tables.keys + database_tables.keys).uniq
|
15
15
|
table_names.each do |table_name|
|
16
|
-
log.
|
16
|
+
log.debug " Processing Table #{table_name}"
|
17
17
|
process_table schema_name, table_name, configuration_tables[table_name] || {}, database_tables[table_name] || {}
|
18
18
|
end
|
19
19
|
end
|
@@ -22,7 +22,7 @@ module DynamicMigrations
|
|
22
22
|
# If the table exists in the configuration but not in the database
|
23
23
|
# then we have to create it.
|
24
24
|
if configuration_table[:exists] == true && !database_table[:exists]
|
25
|
-
log.
|
25
|
+
log.debug " Table `#{table_name}` exists in configuration but not in the database"
|
26
26
|
|
27
27
|
# a migration to create the table
|
28
28
|
table = @database.configured_schema(schema_name).table(table_name)
|
@@ -35,7 +35,7 @@ module DynamicMigrations
|
|
35
35
|
# If the schema exists in the database but not in the configuration
|
36
36
|
# then we need to delete it.
|
37
37
|
elsif database_table[:exists] == true && !configuration_table[:exists]
|
38
|
-
log.
|
38
|
+
log.debug " Table `#{table_name}` exists in database but not in the configuration"
|
39
39
|
|
40
40
|
# we process everything else before we drop the table, because the other
|
41
41
|
# database objects are dependent on the table
|
@@ -48,15 +48,15 @@ module DynamicMigrations
|
|
48
48
|
# If the table exists in both the configuration and database representations
|
49
49
|
# but the description is different then we need to update the description.
|
50
50
|
elsif configuration_table[:description][:matches] == false
|
51
|
-
log.
|
51
|
+
log.debug " Table `#{table_name}` exists in both configuration and the database"
|
52
52
|
|
53
53
|
table = @database.configured_schema(schema_name).table(table_name)
|
54
54
|
# if the description was removed
|
55
55
|
if configuration_table[:description].nil?
|
56
|
-
log.
|
56
|
+
log.debug " Table `#{table_name}` description exists in database but not in the configuration"
|
57
57
|
@generator.remove_table_comment table
|
58
58
|
else
|
59
|
-
log.
|
59
|
+
log.debug " Table `#{table_name}` description does not match"
|
60
60
|
@generator.set_table_comment table
|
61
61
|
end
|
62
62
|
|
@@ -64,7 +64,7 @@ module DynamicMigrations
|
|
64
64
|
process_dependents schema_name, table_name, configuration_table, database_table
|
65
65
|
|
66
66
|
else
|
67
|
-
log.
|
67
|
+
log.debug " Table `#{table_name}` exists in both configuration and the database"
|
68
68
|
# process everything else
|
69
69
|
process_dependents schema_name, table_name, configuration_table, database_table
|
70
70
|
|
@@ -11,7 +11,7 @@ module DynamicMigrations
|
|
11
11
|
# if the schema exists in the configuration but not in the database
|
12
12
|
# then we have to create it
|
13
13
|
if configuration_schema[:exists] == true && !database_schema[:exists]
|
14
|
-
log.
|
14
|
+
log.debug "Schema `#{schema_name}` exists in configuration but not in the database"
|
15
15
|
|
16
16
|
# a migration to create the schema
|
17
17
|
schema = @database.configured_schema schema_name
|
@@ -26,7 +26,7 @@ module DynamicMigrations
|
|
26
26
|
# if the schema exists in the database but not in the configuration
|
27
27
|
# then we need to delete it
|
28
28
|
elsif database_schema[:exists] == true && !configuration_schema[:exists]
|
29
|
-
log.
|
29
|
+
log.debug "Schema `#{schema_name}` exists in database but not in the configuration"
|
30
30
|
# we process the tables and functions before we drop the schema
|
31
31
|
# as this will drop any dependencies on the schema
|
32
32
|
process_functions schema_name, {}, database_schema[:functions]
|
@@ -40,7 +40,7 @@ module DynamicMigrations
|
|
40
40
|
# if the schema exists in both the configuration and database representations
|
41
41
|
# then we just need to process the tables and functions
|
42
42
|
else
|
43
|
-
log.
|
43
|
+
log.debug "Schema `#{schema_name}` exists in both configuration and the database"
|
44
44
|
process_functions schema_name, configuration_schema[:functions], database_schema[:functions]
|
45
45
|
process_enums schema_name, configuration_schema[:enums], database_schema[:enums]
|
46
46
|
process_tables schema_name, configuration_schema[:tables], database_schema[:tables]
|
@@ -40,19 +40,19 @@ module DynamicMigrations
|
|
40
40
|
|
41
41
|
def migrations
|
42
42
|
# process all the extensions
|
43
|
-
log.
|
43
|
+
log.debug "Processing Extensions"
|
44
44
|
extension_names = differences[:configuration][:extensions].keys
|
45
45
|
extension_names.each do |extension_name|
|
46
|
-
log.
|
46
|
+
log.debug "Processing Extension `#{extension_name}`"
|
47
47
|
process_extension extension_name, differences[:configuration][:extensions][extension_name], differences[:database][:extensions][extension_name]
|
48
48
|
end
|
49
49
|
|
50
50
|
# process all the schemas (we can fetch the schema names from either the
|
51
51
|
# configuration or the database object)
|
52
|
-
log.
|
52
|
+
log.debug "Processing Schemas"
|
53
53
|
schema_names = differences[:configuration][:schemas].keys
|
54
54
|
schema_names.each do |schema_name|
|
55
|
-
log.
|
55
|
+
log.debug "Processing Schema `#{schema_name}`"
|
56
56
|
process_schema schema_name, differences[:configuration][:schemas][schema_name], differences[:database][:schemas][schema_name]
|
57
57
|
end
|
58
58
|
|
@@ -33,18 +33,18 @@ module DynamicMigrations
|
|
33
33
|
# return a hash representing any differenced betweek the loaded and configured
|
34
34
|
# versions of the current database
|
35
35
|
def to_h
|
36
|
-
log.info "Building differences between configured and loaded database structure
|
36
|
+
log.info "Building differences between configured and loaded database structure"
|
37
37
|
|
38
38
|
# build progressively, so we can add logging around the two different opperations
|
39
39
|
results = {}
|
40
40
|
|
41
|
-
log.info "Comparing configured database structure to loaded database structure
|
41
|
+
log.info "Comparing configured database structure to loaded database structure"
|
42
42
|
results[:configuration] = {
|
43
43
|
schemas: self.class.compare_schemas(@database.configured_schemas_hash, @database.loaded_schemas_hash),
|
44
44
|
extensions: self.class.compare_extensions(@database.configured_extensions, @database.loaded_extensions)
|
45
45
|
}
|
46
46
|
|
47
|
-
log.info "Comparing loaded database structure to configured database structure
|
47
|
+
log.info "Comparing loaded database structure to configured database structure"
|
48
48
|
results[:database] = {
|
49
49
|
schemas: self.class.compare_schemas(@database.loaded_schemas_hash, @database.configured_schemas_hash),
|
50
50
|
extensions: self.class.compare_extensions(@database.loaded_extensions, @database.configured_extensions)
|
@@ -53,7 +53,7 @@ module DynamicMigrations
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.compare_extensions extensions, comparison_extensions
|
56
|
-
log.info "Comparing Extensions
|
56
|
+
log.info "Comparing Extensions"
|
57
57
|
|
58
58
|
result = {}
|
59
59
|
# the extensions
|
@@ -76,7 +76,7 @@ module DynamicMigrations
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def self.compare_schemas schemas, comparison_schemas
|
79
|
-
log.info "Comparing Schemas
|
79
|
+
log.info "Comparing Schemas"
|
80
80
|
|
81
81
|
result = {}
|
82
82
|
# the base schemas
|
@@ -118,7 +118,7 @@ module DynamicMigrations
|
|
118
118
|
# an object which represents the provided `tables` and any differences
|
119
119
|
# between it and the `comparison_tables`
|
120
120
|
def self.compare_tables tables, comparison_tables
|
121
|
-
log.
|
121
|
+
log.debug "Comparing Tables"
|
122
122
|
|
123
123
|
result = {}
|
124
124
|
# the base tables
|
@@ -143,7 +143,7 @@ module DynamicMigrations
|
|
143
143
|
def self.compare_table table, comparison_table
|
144
144
|
raise TableRequiredError if table.nil?
|
145
145
|
|
146
|
-
log.
|
146
|
+
log.debug "Comparing Table `#{table.name}`"
|
147
147
|
|
148
148
|
primary_key = table.has_primary_key? ? table.primary_key : nil
|
149
149
|
if comparison_table
|
@@ -187,7 +187,7 @@ module DynamicMigrations
|
|
187
187
|
# an object which represents the provided `functions` and any differences
|
188
188
|
# between it and the `comparison_functions`
|
189
189
|
def self.compare_functions functions, comparison_functions
|
190
|
-
log.
|
190
|
+
log.debug "Comparing Functions"
|
191
191
|
|
192
192
|
result = {}
|
193
193
|
# the base functions
|
@@ -212,7 +212,7 @@ module DynamicMigrations
|
|
212
212
|
# an object which represents the provided `enums` and any differences
|
213
213
|
# between it and the `comparison_enums`
|
214
214
|
def self.compare_enums enums, comparison_enums
|
215
|
-
log.
|
215
|
+
log.debug "Comparing Enums"
|
216
216
|
|
217
217
|
result = {}
|
218
218
|
# the base enums
|
@@ -237,7 +237,7 @@ module DynamicMigrations
|
|
237
237
|
# an object which represents the provided `columns` and any differences
|
238
238
|
# between it and the `comparison_columns`
|
239
239
|
def self.compare_columns columns, comparison_columns
|
240
|
-
log.
|
240
|
+
log.debug "Comparing Columns"
|
241
241
|
|
242
242
|
result = {}
|
243
243
|
# the base columns
|
@@ -266,7 +266,7 @@ module DynamicMigrations
|
|
266
266
|
# an object which represents the provided `triggers` and any differences
|
267
267
|
# between it and the `comparison_triggers`
|
268
268
|
def self.compare_triggers triggers, comparison_triggers
|
269
|
-
log.
|
269
|
+
log.debug "Comparing Triggers"
|
270
270
|
|
271
271
|
result = {}
|
272
272
|
# the base triggers
|
@@ -299,7 +299,7 @@ module DynamicMigrations
|
|
299
299
|
# an object which represents the provided `unique_constraints` and any differences
|
300
300
|
# between it and the `comparison_unique_constraints`
|
301
301
|
def self.compare_unique_constraints unique_constraints, comparison_unique_constraints
|
302
|
-
log.
|
302
|
+
log.debug "Comparing Unique Constraints"
|
303
303
|
|
304
304
|
result = {}
|
305
305
|
# the base unique_constraints
|
@@ -327,7 +327,7 @@ module DynamicMigrations
|
|
327
327
|
# an object which represents the provided `indexes` and any differences
|
328
328
|
# between it and the `comparison_indexes`
|
329
329
|
def self.compare_indexes indexes, comparison_indexes
|
330
|
-
log.
|
330
|
+
log.debug "Comparing Indexes"
|
331
331
|
|
332
332
|
result = {}
|
333
333
|
# the base indexes
|
@@ -358,7 +358,7 @@ module DynamicMigrations
|
|
358
358
|
# an object which represents the provided `validations` and any differences
|
359
359
|
# between it and the `comparison_validations`
|
360
360
|
def self.compare_validations validations, comparison_validations
|
361
|
-
log.
|
361
|
+
log.debug "Comparing Validations"
|
362
362
|
|
363
363
|
result = {}
|
364
364
|
# the base validations
|
@@ -367,9 +367,7 @@ module DynamicMigrations
|
|
367
367
|
result[name] = compare_record validation, comparison_validations[name], [
|
368
368
|
:normalized_check_clause,
|
369
369
|
:column_names,
|
370
|
-
:description
|
371
|
-
:deferrable,
|
372
|
-
:initially_deferred
|
370
|
+
:description
|
373
371
|
]
|
374
372
|
end
|
375
373
|
# look for any validations in the comparison list which were not in the base list
|
@@ -387,7 +385,7 @@ module DynamicMigrations
|
|
387
385
|
# an object which represents the provided `foreign_key_constraints` and any differences
|
388
386
|
# between it and the `comparison_foreign_key_constraints`
|
389
387
|
def self.compare_foreign_key_constraints foreign_key_constraints, comparison_foreign_key_constraints
|
390
|
-
log.
|
388
|
+
log.debug "Comparing Foreign Key Constraints"
|
391
389
|
|
392
390
|
result = {}
|
393
391
|
# the base foreign_key_constraints
|
@@ -428,13 +426,20 @@ module DynamicMigrations
|
|
428
426
|
else
|
429
427
|
type = base.class.name.split("::").last
|
430
428
|
name = base.is_a?(Schema::Table::PrimaryKey) ? nil : base.name
|
431
|
-
log.
|
429
|
+
log.debug " Comparing #{type} `#{name}`"
|
432
430
|
|
433
431
|
result = {}
|
434
432
|
method_list.each do |method_name|
|
435
|
-
log.
|
433
|
+
log.debug " Comparing `#{method_name}`"
|
436
434
|
|
437
435
|
matches = (comparison && comparison.send(method_name) == base.send(method_name)) || false
|
436
|
+
|
437
|
+
unless matches
|
438
|
+
log.debug " Values are different"
|
439
|
+
log.debug " Base Value: `#{base.send(method_name)}`"
|
440
|
+
log.debug " Other Value: `#{comparison.nil? ? "nil" : comparison.send(method_name)}`"
|
441
|
+
end
|
442
|
+
|
438
443
|
result[method_name] = {
|
439
444
|
value: base.send(method_name),
|
440
445
|
matches: matches
|
@@ -152,8 +152,8 @@ module DynamicMigrations
|
|
152
152
|
on_delete = nil
|
153
153
|
end
|
154
154
|
|
155
|
-
deferrable = row["deferrable"] == "
|
156
|
-
initially_deferred = row["initially_deferred"] == "
|
155
|
+
deferrable = row["deferrable"] == "t"
|
156
|
+
initially_deferred = row["initially_deferred"] == "t"
|
157
157
|
|
158
158
|
index_type = if row["index_type"].nil?
|
159
159
|
nil
|
@@ -60,7 +60,7 @@ module DynamicMigrations
|
|
60
60
|
|
61
61
|
# add any validations
|
62
62
|
table_validations&.each do |validation_name, validation_definition|
|
63
|
-
table.add_validation validation_name, validation_definition[:columns], validation_definition[:check_clause], description: validation_definition[:description]
|
63
|
+
table.add_validation validation_name, validation_definition[:columns], validation_definition[:check_clause], description: validation_definition[:description]
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -19,6 +19,9 @@ module DynamicMigrations
|
|
19
19
|
class ValueMustBeStringError < StandardError
|
20
20
|
end
|
21
21
|
|
22
|
+
class EnumValueTooLongError < StandardError
|
23
|
+
end
|
24
|
+
|
22
25
|
attr_reader :schema
|
23
26
|
attr_reader :name
|
24
27
|
attr_reader :values
|
@@ -47,7 +50,7 @@ module DynamicMigrations
|
|
47
50
|
|
48
51
|
unless description.nil?
|
49
52
|
raise ExpectedStringError, description unless description.is_a? String
|
50
|
-
@description = description.strip
|
53
|
+
@description = description.strip.freeze
|
51
54
|
@description = nil if description == ""
|
52
55
|
end
|
53
56
|
end
|
@@ -61,7 +64,11 @@ module DynamicMigrations
|
|
61
64
|
raise ValueAlreadyExistsError, "Value `#{value}` already exists in enum `#{name}`"
|
62
65
|
end
|
63
66
|
|
64
|
-
|
67
|
+
if value.length > 63
|
68
|
+
raise EnumValueTooLongError, "Value `#{value}` must be less than 64 characters"
|
69
|
+
end
|
70
|
+
|
71
|
+
@values << value.freeze
|
65
72
|
end
|
66
73
|
|
67
74
|
# returns true if this enum has a description, otehrwise false
|
@@ -37,11 +37,11 @@ module DynamicMigrations
|
|
37
37
|
unless definition.is_a?(String) && definition.strip != "" && definition.strip.end_with?("END;", "END")
|
38
38
|
raise ExpectedDefinitionError, "Definition must be a string, and end with `END;`. Definition provided:\n#{definition}"
|
39
39
|
end
|
40
|
-
@definition = definition.strip
|
40
|
+
@definition = definition.strip.freeze
|
41
41
|
|
42
42
|
unless description.nil?
|
43
43
|
raise ExpectedStringError, description unless description.is_a? String
|
44
|
-
@description = description.strip
|
44
|
+
@description = description.strip.freeze
|
45
45
|
@description = nil if description == ""
|
46
46
|
end
|
47
47
|
end
|
@@ -14,6 +14,9 @@ module DynamicMigrations
|
|
14
14
|
class UnexpectedEnumError < StandardError
|
15
15
|
end
|
16
16
|
|
17
|
+
class InvalidNameError < StandardError
|
18
|
+
end
|
19
|
+
|
17
20
|
attr_reader :table
|
18
21
|
attr_reader :name
|
19
22
|
attr_reader :data_type
|
@@ -29,7 +32,8 @@ module DynamicMigrations
|
|
29
32
|
raise ExpectedTableError, table unless table.is_a? Table
|
30
33
|
@table = table
|
31
34
|
|
32
|
-
raise
|
35
|
+
raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
|
36
|
+
raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
|
33
37
|
@name = name
|
34
38
|
|
35
39
|
raise ExpectedSymbolError, data_type unless data_type.is_a? Symbol
|
@@ -44,7 +48,7 @@ module DynamicMigrations
|
|
44
48
|
|
45
49
|
unless description.nil?
|
46
50
|
raise ExpectedStringError, description unless description.is_a? String
|
47
|
-
@description = description.strip
|
51
|
+
@description = description.strip.freeze
|
48
52
|
@description = nil if description == ""
|
49
53
|
end
|
50
54
|
|
@@ -50,12 +50,6 @@ module DynamicMigrations
|
|
50
50
|
else
|
51
51
|
raise ModuleIncludedIntoUnexpectedTargetError, included_target
|
52
52
|
end
|
53
|
-
# sort the hash so that the columns are in alphabetical order by name
|
54
|
-
sorted_columns = {}
|
55
|
-
@columns.keys.sort.each do |name|
|
56
|
-
sorted_columns[name] = @columns[name]
|
57
|
-
end
|
58
|
-
@columns = sorted_columns
|
59
53
|
# return the new column
|
60
54
|
new_column
|
61
55
|
end
|
@@ -20,6 +20,9 @@ module DynamicMigrations
|
|
20
20
|
class UnexpectedReferentialActionError < StandardError
|
21
21
|
end
|
22
22
|
|
23
|
+
class InvalidNameError < StandardError
|
24
|
+
end
|
25
|
+
|
23
26
|
attr_reader :table
|
24
27
|
attr_reader :foreign_table
|
25
28
|
attr_reader :name
|
@@ -64,12 +67,13 @@ module DynamicMigrations
|
|
64
67
|
add_column column, true
|
65
68
|
end
|
66
69
|
|
67
|
-
raise
|
70
|
+
raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
|
71
|
+
raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
|
68
72
|
@name = name
|
69
73
|
|
70
74
|
unless description.nil?
|
71
75
|
raise ExpectedStringError, description unless description.is_a? String
|
72
|
-
@description = description.strip
|
76
|
+
@description = description.strip.freeze
|
73
77
|
@description = nil if description == ""
|
74
78
|
end
|
75
79
|
|
@@ -30,6 +30,9 @@ module DynamicMigrations
|
|
30
30
|
class DuplicateColumnError < StandardError
|
31
31
|
end
|
32
32
|
|
33
|
+
class InvalidNameError < StandardError
|
34
|
+
end
|
35
|
+
|
33
36
|
attr_reader :table
|
34
37
|
attr_reader :name
|
35
38
|
attr_reader :unique
|
@@ -56,12 +59,13 @@ module DynamicMigrations
|
|
56
59
|
add_column column
|
57
60
|
end
|
58
61
|
|
59
|
-
raise
|
62
|
+
raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
|
63
|
+
raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
|
60
64
|
@name = name
|
61
65
|
|
62
66
|
unless description.nil?
|
63
67
|
raise ExpectedStringError, description unless description.is_a? String
|
64
|
-
@description = description.strip
|
68
|
+
@description = description.strip.freeze
|
65
69
|
@description = nil if description == ""
|
66
70
|
end
|
67
71
|
|
@@ -70,7 +74,7 @@ module DynamicMigrations
|
|
70
74
|
|
71
75
|
unless where.nil?
|
72
76
|
raise ExpectedStringError, where unless where.is_a? String
|
73
|
-
@where = where
|
77
|
+
@where = where.freeze
|
74
78
|
end
|
75
79
|
|
76
80
|
raise UnexpectedIndexTypeError, type unless INDEX_TYPES.include?(type)
|
@@ -20,6 +20,9 @@ module DynamicMigrations
|
|
20
20
|
class DuplicateColumnError < StandardError
|
21
21
|
end
|
22
22
|
|
23
|
+
class InvalidNameError < StandardError
|
24
|
+
end
|
25
|
+
|
23
26
|
attr_reader :table
|
24
27
|
attr_reader :name
|
25
28
|
attr_reader :description
|
@@ -40,12 +43,13 @@ module DynamicMigrations
|
|
40
43
|
add_column column
|
41
44
|
end
|
42
45
|
|
43
|
-
raise
|
46
|
+
raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
|
47
|
+
raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
|
44
48
|
@name = name
|
45
49
|
|
46
50
|
unless description.nil?
|
47
51
|
raise ExpectedStringError, description unless description.is_a? String
|
48
|
-
@description = description.strip
|
52
|
+
@description = description.strip.freeze
|
49
53
|
@description = nil if description == ""
|
50
54
|
end
|
51
55
|
end
|
@@ -41,6 +41,9 @@ module DynamicMigrations
|
|
41
41
|
class UnnormalizableActionConditionError < StandardError
|
42
42
|
end
|
43
43
|
|
44
|
+
class InvalidNameError < StandardError
|
45
|
+
end
|
46
|
+
|
44
47
|
attr_reader :table
|
45
48
|
attr_reader :name
|
46
49
|
attr_reader :event_manipulation
|
@@ -63,9 +66,8 @@ module DynamicMigrations
|
|
63
66
|
end
|
64
67
|
@table = table
|
65
68
|
|
66
|
-
unless name.is_a? Symbol
|
67
|
-
|
68
|
-
end
|
69
|
+
raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
|
70
|
+
raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
|
69
71
|
@name = name
|
70
72
|
|
71
73
|
unless [:before, :after].include? action_timing
|
@@ -93,12 +95,12 @@ module DynamicMigrations
|
|
93
95
|
unless action_condition.nil? || action_condition.is_a?(String)
|
94
96
|
raise ExpectedStringError, action_condition
|
95
97
|
end
|
96
|
-
@action_condition = action_condition&.strip
|
98
|
+
@action_condition = action_condition&.strip&.freeze
|
97
99
|
|
98
100
|
unless parameters.is_a?(Array) && parameters.all? { |p| p.is_a? String }
|
99
101
|
raise UnexpectedParametersError, "unexpected parameters `#{parameters}`, currently only an array of strings is supported"
|
100
102
|
end
|
101
|
-
@parameters = parameters
|
103
|
+
@parameters = parameters.map(&:freeze)
|
102
104
|
|
103
105
|
unless [:row, :statement].include? action_orientation
|
104
106
|
raise UnexpectedActionOrientationError, action_orientation
|
@@ -128,7 +130,7 @@ module DynamicMigrations
|
|
128
130
|
|
129
131
|
unless description.nil?
|
130
132
|
raise ExpectedStringError, description unless description.is_a? String
|
131
|
-
@description = description.strip
|
133
|
+
@description = description.strip.freeze
|
132
134
|
@description = nil if description == ""
|
133
135
|
end
|
134
136
|
|
@@ -166,7 +168,7 @@ module DynamicMigrations
|
|
166
168
|
unless new_action_condition.nil? || new_action_condition.is_a?(String)
|
167
169
|
raise ExpectedStringError, new_action_condition
|
168
170
|
end
|
169
|
-
@action_condition = new_action_condition&.strip
|
171
|
+
@action_condition = new_action_condition&.strip&.freeze
|
170
172
|
end
|
171
173
|
|
172
174
|
def add_parameter new_parameter
|
@@ -224,7 +226,7 @@ module DynamicMigrations
|
|
224
226
|
$$ BEGIN END $$;
|
225
227
|
SQL
|
226
228
|
|
227
|
-
temp_action_condition = action_condition
|
229
|
+
temp_action_condition = action_condition.dup
|
228
230
|
# string replace any real enum names with their temp enum names
|
229
231
|
temp_enums.each do |temp_enum_name, enum|
|
230
232
|
temp_action_condition.gsub!("::#{enum.name}", "::#{temp_enum_name}")
|
@@ -17,14 +17,14 @@ module DynamicMigrations
|
|
17
17
|
# returns the trigger object for the provided trigger name, and raises an
|
18
18
|
# error if the trigger does not exist
|
19
19
|
def trigger name
|
20
|
-
raise
|
20
|
+
raise Trigger::InvalidNameError, name unless name.is_a? Symbol
|
21
21
|
raise TriggerDoesNotExistError unless has_trigger? name
|
22
22
|
@triggers[name]
|
23
23
|
end
|
24
24
|
|
25
25
|
# returns true if this table has a trigger with the provided name, otherwise false
|
26
26
|
def has_trigger? name
|
27
|
-
raise
|
27
|
+
raise Trigger::InvalidNameError, name unless name.is_a? Symbol
|
28
28
|
@triggers.key? name
|
29
29
|
end
|
30
30
|
|