dynamic_migrations 3.8.7 → 3.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/lib/dynamic_migrations/active_record/migrators/validation.rb +2 -20
  4. data/lib/dynamic_migrations/postgres/generator/fragment.rb +9 -2
  5. data/lib/dynamic_migrations/postgres/generator/validation.rb +1 -3
  6. data/lib/dynamic_migrations/postgres/generator/validation_template_base.rb +1 -7
  7. data/lib/dynamic_migrations/postgres/server/database/differences.rb +8 -3
  8. data/lib/dynamic_migrations/postgres/server/database/keys_and_unique_constraints_loader.rb +2 -2
  9. data/lib/dynamic_migrations/postgres/server/database/loaded_schemas_builder.rb +1 -1
  10. data/lib/dynamic_migrations/postgres/server/database/schema/enum.rb +2 -2
  11. data/lib/dynamic_migrations/postgres/server/database/schema/function.rb +2 -2
  12. data/lib/dynamic_migrations/postgres/server/database/schema/table/column.rb +6 -2
  13. data/lib/dynamic_migrations/postgres/server/database/schema/table/columns.rb +0 -6
  14. data/lib/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraint.rb +6 -2
  15. data/lib/dynamic_migrations/postgres/server/database/schema/table/index.rb +7 -3
  16. data/lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb +6 -2
  17. data/lib/dynamic_migrations/postgres/server/database/schema/table/trigger.rb +10 -8
  18. data/lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb +2 -2
  19. data/lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb +6 -2
  20. data/lib/dynamic_migrations/postgres/server/database/schema/table/validation.rb +12 -19
  21. data/lib/dynamic_migrations/postgres/server/database/schema/table.rb +1 -1
  22. data/lib/dynamic_migrations/postgres/server/database/validations_loader.rb +1 -3
  23. data/lib/dynamic_migrations/version.rb +1 -1
  24. data/sig/dynamic_migrations/active_record/migrators/validation.rbs +1 -1
  25. data/sig/dynamic_migrations/postgres/generator/fragment.rbs +3 -0
  26. data/sig/dynamic_migrations/postgres/generator/validation_template_base.rbs +0 -1
  27. data/sig/dynamic_migrations/postgres/server/database/schema/table/column.rbs +3 -0
  28. data/sig/dynamic_migrations/postgres/server/database/schema/table/foreign_key_constraint.rbs +3 -0
  29. data/sig/dynamic_migrations/postgres/server/database/schema/table/index.rbs +3 -0
  30. data/sig/dynamic_migrations/postgres/server/database/schema/table/primary_key.rbs +3 -0
  31. data/sig/dynamic_migrations/postgres/server/database/schema/table/trigger.rbs +3 -0
  32. data/sig/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rbs +3 -0
  33. data/sig/dynamic_migrations/postgres/server/database/schema/table/validation.rbs +4 -3
  34. metadata +2 -3
  35. data/lib/dynamic_migrations/name_helper.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 443be07abb74aef74bd5d94de87ab2be7f227f81e1c401cb7bf8ebc55bc1c6af
4
- data.tar.gz: f93c398273cb1ae28cf6d5b257adeda625f3c732952f327692fb3ef076798f7f
3
+ metadata.gz: d822c8e95efe29d0f03f07162f27909ba4222ab4be98c421d64bd167fe923443
4
+ data.tar.gz: 88a20111dae2a34872d0759f47a0c8c29eab87d354ebb7a55d33152c9d06c6e3
5
5
  SHA512:
6
- metadata.gz: c35b3c1d1834fea80cfdc2c9b14f611b5d76f005b408e0cbfd7592216780454647c519fbc5113bcd5a946a578320417cde47eeaa785fc097dc5062b79a310522
7
- data.tar.gz: '09780db07d086da4fc27c5187770248b174d91e7c89a6f3021f1a87e42f97c3b4cf091e7ed510ef7e853e4da360f5b359bbc91a7375b94edd55d09c52e0f905a'
6
+ metadata.gz: 2210081126891f62ebadb6dd9f9f53cafd5cdd7ae196558b00e94ffdf91b64b1686d65c95ec07357ee8043ba1e8c698812ed07503d8b46287ab5496e26beb46d
7
+ data.tar.gz: eb23900019d373320e0f2510eadd2714c1c2c4324af0b0a4f68886754204deb7ebc0de11f833bf43b0a53b38f80448b70370ccd57ca55005c97715c397f4b579
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.8.8](https://github.com/craigulliott/dynamic_migrations/compare/v3.8.7...v3.8.8) (2023-10-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * adding a specific error type for invalid names ([12df7bd](https://github.com/craigulliott/dynamic_migrations/commit/12df7bddcb947d3ab5b1b00eebefdda0a3ce15ac))
9
+ * fixed bug where check_clause and action_condition were being modified, also freezing strings to prevent similar bugs in the future ([dc1191b](https://github.com/craigulliott/dynamic_migrations/commit/dc1191b7e219b73da8469742259686721265a2a7))
10
+ * removed arbitrary column name sorting, as we want migrations to create columns in the order they were added ([e9a515e](https://github.com/craigulliott/dynamic_migrations/commit/e9a515eb9dbf16ef5a5e77ca0084a6514690530b))
11
+ * removing deferrable and initially deferred from check constraints because postgres doesn't support them ([945aef2](https://github.com/craigulliott/dynamic_migrations/commit/945aef2419fd5f55a0551929244f3f9b0a29a905))
12
+ * should not have assumed enums in the same schema use their short name, enums are always referenced by their full name (including schema) ([a9863ba](https://github.com/craigulliott/dynamic_migrations/commit/a9863ba49727e5016c8eae74f5f2a6e7ab8c1042))
13
+ * we were not resolving the correct deferred and initially_deferred values when loading existing database structure ([02c539a](https://github.com/craigulliott/dynamic_migrations/commit/02c539a8ea153cde6d06f6be6d8fdb0aaf851f40))
14
+
3
15
  ## [3.8.7](https://github.com/craigulliott/dynamic_migrations/compare/v3.8.6...v3.8.7) (2023-10-09)
4
16
 
5
17
 
@@ -3,7 +3,7 @@ module DynamicMigrations
3
3
  module Migrators
4
4
  module Validation
5
5
  # this exists because because the standard rails migration does not support deffered constraints
6
- def add_validation table_name, name:, initially_deferred: false, deferrable: false, comment: nil, &block
6
+ def add_validation table_name, name:, comment: nil, &block
7
7
  unless block
8
8
  raise MissingFunctionBlockError, "create_function requires a block"
9
9
  end
@@ -12,28 +12,10 @@ module DynamicMigrations
12
12
  sql = block.call.strip
13
13
  end
14
14
 
15
- if initially_deferred == true && deferrable == false
16
- raise DeferrableOptionsError, "A constraint can only be initially deferred if it is also deferrable"
17
- end
18
-
19
- # allow it to be deferred, and defer it by default
20
- deferrable_sql = if initially_deferred
21
- "DEFERRABLE INITIALLY DEFERRED"
22
-
23
- # allow it to be deferred, but do not deferr by default
24
- elsif deferrable
25
- "DEFERRABLE INITIALLY IMMEDIATE"
26
-
27
- # it can not be deferred (this is the default)
28
- else
29
- "NOT DEFERRABLE"
30
- end
31
-
32
15
  execute <<~SQL
33
16
  ALTER TABLE #{table_name}
34
17
  ADD CONSTRAINT #{name}
35
- CHECK (#{sql})
36
- #{deferrable_sql};
18
+ CHECK (#{sql});
37
19
  SQL
38
20
 
39
21
  if comment.is_a? String
@@ -5,6 +5,9 @@ module DynamicMigrations
5
5
  class InvalidNameError < StandardError
6
6
  end
7
7
 
8
+ class ContentRequiredError < StandardError
9
+ end
10
+
8
11
  attr_reader :schema_name
9
12
  attr_reader :table_name
10
13
  attr_reader :migration_method
@@ -33,8 +36,12 @@ module DynamicMigrations
33
36
  @object_name = object_name
34
37
 
35
38
  @migration_method = migration_method
36
- @code_comment = code_comment
37
- @content = content
39
+ @code_comment = code_comment&.freeze
40
+
41
+ if content.nil?
42
+ raise ContentRequiredError, "Content is required for a fragment"
43
+ end
44
+ @content = content.freeze
38
45
  end
39
46
 
40
47
  # Returns a string representation of the fragment for use in the final
@@ -38,9 +38,7 @@ module DynamicMigrations
38
38
  else
39
39
 
40
40
  options = {
41
- name: ":#{validation.name}",
42
- deferrable: validation.deferrable,
43
- initially_deferred: validation.initially_deferred
41
+ name: ":#{validation.name}"
44
42
  }
45
43
 
46
44
  if validation.description.nil?
@@ -10,17 +10,11 @@ module DynamicMigrations
10
10
 
11
11
  def initialize validation, code_comment
12
12
  @validation = validation
13
- @code_comment = code_comment
13
+ @code_comment = code_comment&.freeze
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def assert_not_deferred!
19
- if @validation.initially_deferred || @validation.deferrable
20
- raise TemplateError, "#{self.class.name} validation template requires constraints to be are not deferrable"
21
- end
22
- end
23
-
24
18
  def assert_column_count! count = 1
25
19
  if @validation.columns.count != count
26
20
  raise TemplateError, "#{self.class.name} validation template requires a validation with only #{count} column"
@@ -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
@@ -435,6 +433,13 @@ module DynamicMigrations
435
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"] == "TRUE"
156
- initially_deferred = row["initially_deferred"] == "TRUE"
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], deferrable: validation_definition[:deferrable], initially_deferred: validation_definition[:initially_deferred]
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
@@ -50,7 +50,7 @@ module DynamicMigrations
50
50
 
51
51
  unless description.nil?
52
52
  raise ExpectedStringError, description unless description.is_a? String
53
- @description = description.strip
53
+ @description = description.strip.freeze
54
54
  @description = nil if description == ""
55
55
  end
56
56
  end
@@ -68,7 +68,7 @@ module DynamicMigrations
68
68
  raise EnumValueTooLongError, "Value `#{value}` must be less than 64 characters"
69
69
  end
70
70
 
71
- @values << value
71
+ @values << value.freeze
72
72
  end
73
73
 
74
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 ExpectedSymbolError, name unless name.is_a? Symbol
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 ExpectedSymbolError, name unless name.is_a? Symbol
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 ExpectedSymbolError, name unless name.is_a? Symbol
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 ExpectedSymbolError, name unless name.is_a? Symbol
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
- raise ExpectedSymbolError, name
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 ExpectedSymbolError, name unless name.is_a? Symbol
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 ExpectedSymbolError, name unless name.is_a? Symbol
27
+ raise Trigger::InvalidNameError, name unless name.is_a? Symbol
28
28
  @triggers.key? name
29
29
  end
30
30
 
@@ -23,6 +23,9 @@ module DynamicMigrations
23
23
  class DuplicateColumnError < StandardError
24
24
  end
25
25
 
26
+ class InvalidNameError < StandardError
27
+ end
28
+
26
29
  attr_reader :table
27
30
  attr_reader :name
28
31
  attr_reader :deferrable
@@ -45,12 +48,13 @@ module DynamicMigrations
45
48
  add_column column
46
49
  end
47
50
 
48
- raise ExpectedSymbolError, name unless name.is_a? Symbol
51
+ raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
52
+ raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
49
53
  @name = name
50
54
 
51
55
  unless description.nil?
52
56
  raise ExpectedStringError, description unless description.is_a? String
53
- @description = description.strip
57
+ @description = description.strip.freeze
54
58
  @description = nil if description == ""
55
59
  end
56
60
 
@@ -26,25 +26,27 @@ module DynamicMigrations
26
26
  class UnnormalizableCheckClauseError < StandardError
27
27
  end
28
28
 
29
+ class InvalidNameError < StandardError
30
+ end
31
+
29
32
  attr_reader :table
30
33
  attr_reader :name
31
34
  attr_reader :check_clause
32
- attr_reader :deferrable
33
- attr_reader :initially_deferred
34
35
  attr_reader :description
35
36
  attr_reader :template
36
37
 
37
38
  # initialize a new object to represent a validation in a postgres table
38
- def initialize source, table, columns, name, check_clause, description: nil, deferrable: false, initially_deferred: false, template: nil
39
+ def initialize source, table, columns, name, check_clause, description: nil, template: nil
39
40
  super source
40
41
  raise ExpectedTableError, table unless table.is_a? Table
41
42
  @table = table
42
43
 
43
- raise ExpectedSymbolError, name unless name.is_a? Symbol
44
+ raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
45
+ raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
44
46
  @name = name
45
47
 
46
48
  raise ExpectedStringError, check_clause unless check_clause.is_a? String
47
- @check_clause = check_clause.strip
49
+ @check_clause = check_clause.strip.freeze
48
50
 
49
51
  # if this validation is created via configuration (apposed to being loaded) then they can be lazy loaded
50
52
  unless from_configuration? && columns.nil?
@@ -61,16 +63,10 @@ module DynamicMigrations
61
63
 
62
64
  unless description.nil?
63
65
  raise ExpectedStringError, description unless description.is_a? String
64
- @description = description.strip
66
+ @description = description.strip.freeze
65
67
  @description = nil if description == ""
66
68
  end
67
69
 
68
- raise ExpectedBooleanError, deferrable unless [true, false].include?(deferrable)
69
- @deferrable = deferrable
70
-
71
- raise ExpectedBooleanError, initially_deferred unless [true, false].include?(initially_deferred)
72
- @initially_deferred = initially_deferred
73
-
74
70
  unless template.nil?
75
71
  unless Generator::Validation.has_template? template
76
72
  raise UnexpectedTemplateError, "Unrecognised template #{template}"
@@ -96,14 +92,12 @@ module DynamicMigrations
96
92
  end
97
93
 
98
94
  def column_names
99
- columns.map(&:name)
95
+ columns.map(&:name).sort
100
96
  end
101
97
 
102
98
  def differences_descriptions other_validation
103
99
  method_differences_descriptions other_validation, [
104
- :normalized_check_clause,
105
- :deferrable,
106
- :initially_deferred
100
+ :normalized_check_clause
107
101
  ]
108
102
  end
109
103
 
@@ -134,7 +128,7 @@ module DynamicMigrations
134
128
 
135
129
  temp_enums = table.create_temp_table(connection, "validation_normalized_check_clause_temp_table")
136
130
 
137
- temp_check_clause = check_clause
131
+ temp_check_clause = check_clause.dup
138
132
  # string replace any real enum names with their temp enum names
139
133
  temp_enums.each do |temp_enum_name, enum|
140
134
  temp_check_clause.gsub!("::#{enum.name}", "::#{temp_enum_name}")
@@ -182,8 +176,7 @@ module DynamicMigrations
182
176
 
183
177
  # string replace any enum names with their real enum names
184
178
  temp_enums.each do |temp_enum_name, enum|
185
- real_enum_name = (enum.schema == table.schema) ? enum.name : enum.full_name
186
- check_clause_result.gsub!("::#{temp_enum_name}", "::#{real_enum_name}")
179
+ check_clause_result.gsub!("::#{temp_enum_name}", "::#{enum.full_name}")
187
180
  end
188
181
 
189
182
  column_names_result = column_names_string.gsub(/\A\{/, "").gsub(/\}\Z/, "").split(",").map { |column_name| column_name.to_sym }
@@ -43,7 +43,7 @@ module DynamicMigrations
43
43
 
44
44
  unless description.nil?
45
45
  raise ExpectedStringError, description unless description.is_a? String
46
- @description = description.strip
46
+ @description = description.strip.freeze
47
47
  @description = nil if description == ""
48
48
  end
49
49
 
@@ -86,9 +86,7 @@ module DynamicMigrations
86
86
  table[validation_name] = {
87
87
  columns: row["columns"].gsub(/\A\{/, "").gsub(/\}\Z/, "").split(",").map { |column_name| column_name.to_sym },
88
88
  check_clause: check_clause,
89
- description: row["description"],
90
- deferrable: row["deferrable"] == "TRUE",
91
- initially_deferred: row["initially_deferred"] == "TRUE"
89
+ description: row["description"]
92
90
  }
93
91
  end
94
92
  schemas
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamicMigrations
4
- VERSION = "3.8.7"
4
+ VERSION = "3.8.8"
5
5
  end
@@ -5,7 +5,7 @@ module DynamicMigrations
5
5
  module ActiveRecord
6
6
  module Migrators
7
7
  module Validation
8
- def add_validation: (Symbol table_name, name: Symbol, ?initially_deferred: bool, ?deferrable: bool, ?comment: String?) -> void
8
+ def add_validation: (Symbol table_name, name: Symbol, ?comment: String?) -> void
9
9
  def remove_validation: (Symbol table_name, Symbol name) -> void
10
10
  def set_validation_comment: (Symbol table_name, Symbol validation_name, String comment) -> void
11
11
  def remove_validation_comment: (Symbol table_name, Symbol validation_name) -> void
@@ -40,6 +40,9 @@ module DynamicMigrations
40
40
 
41
41
  class InvalidNameError < StandardError
42
42
  end
43
+
44
+ class ContentRequiredError < StandardError
45
+ end
43
46
  end
44
47
  end
45
48
  end
@@ -15,7 +15,6 @@ module DynamicMigrations
15
15
  def fragment_arguments: -> {schema: Postgres::Server::Database::Schema, table: Postgres::Server::Database::Schema::Table, migration_method: Symbol, object: untyped, code_comment: String?, migration: String, dependent_function: Postgres::Server::Database::Schema::Function?}
16
16
 
17
17
  private
18
- def assert_not_deferred!: -> void
19
18
  def assert_column_count!: (?Integer count) -> void
20
19
  def first_column: -> Postgres::Server::Database::Schema::Table::Column
21
20
  def value_from_check_clause: (Regexp regex) -> untyped
@@ -27,6 +27,9 @@ module DynamicMigrations
27
27
 
28
28
  class UnexpectedEnumError < StandardError
29
29
  end
30
+
31
+ class InvalidNameError < StandardError
32
+ end
30
33
  end
31
34
  end
32
35
  end
@@ -43,6 +43,9 @@ module DynamicMigrations
43
43
 
44
44
  class UnexpectedReferentialActionError < StandardError
45
45
  end
46
+
47
+ class InvalidNameError < StandardError
48
+ end
46
49
  end
47
50
  end
48
51
  end
@@ -53,6 +53,9 @@ module DynamicMigrations
53
53
 
54
54
  class DuplicateColumnError < StandardError
55
55
  end
56
+
57
+ class InvalidNameError < StandardError
58
+ end
56
59
  end
57
60
  end
58
61
  end
@@ -31,6 +31,9 @@ module DynamicMigrations
31
31
 
32
32
  class DuplicateColumnError < StandardError
33
33
  end
34
+
35
+ class InvalidNameError < StandardError
36
+ end
34
37
  end
35
38
  end
36
39
  end
@@ -65,6 +65,9 @@ module DynamicMigrations
65
65
 
66
66
  class UnnormalizableActionConditionError < StandardError
67
67
  end
68
+
69
+ class InvalidNameError < StandardError
70
+ end
68
71
  end
69
72
  end
70
73
  end
@@ -40,6 +40,9 @@ module DynamicMigrations
40
40
 
41
41
  class DuplicateColumnError < StandardError
42
42
  end
43
+
44
+ class InvalidNameError < StandardError
45
+ end
43
46
  end
44
47
  end
45
48
  end
@@ -11,12 +11,10 @@ module DynamicMigrations
11
11
  attr_reader table: Table
12
12
  attr_reader name: Symbol
13
13
  attr_reader check_clause: String
14
- attr_reader deferrable: bool
15
- attr_reader initially_deferred: bool
16
14
  attr_reader description: String?
17
15
  attr_reader template: Symbol?
18
16
 
19
- def initialize: (database_or_configuration source, Table table, Array[Column]? columns, Symbol name, String check_clause, ?deferrable: bool, ?initially_deferred: bool, ?description: String?, ?template: Symbol?) -> void
17
+ def initialize: (database_or_configuration source, Table table, Array[Column]? columns, Symbol name, String check_clause, ?description: String?, ?template: Symbol?) -> void
20
18
  def columns: -> Array[Column]
21
19
  def column_names: -> Array[Symbol]
22
20
  def has_description?: -> bool
@@ -50,6 +48,9 @@ module DynamicMigrations
50
48
 
51
49
  class UnnormalizableCheckClauseError < StandardError
52
50
  end
51
+
52
+ class InvalidNameError < StandardError
53
+ end
53
54
  end
54
55
  end
55
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.7
4
+ version: 3.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ulliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-09 00:00:00.000000000 Z
11
+ date: 2023-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -96,7 +96,6 @@ files:
96
96
  - lib/dynamic_migrations/expected_symbol_error.rb
97
97
  - lib/dynamic_migrations/invalid_source_error.rb
98
98
  - lib/dynamic_migrations/module_included_into_unexpected_target_error.rb
99
- - lib/dynamic_migrations/name_helper.rb
100
99
  - lib/dynamic_migrations/postgres.rb
101
100
  - lib/dynamic_migrations/postgres/connections.rb
102
101
  - lib/dynamic_migrations/postgres/generator.rb
@@ -1,13 +0,0 @@
1
- module DynamicMigrations
2
- module NameHelper
3
- # shortens a table name like 'invoice_subscription_prepayments' to 'inv_sub_pre'
4
- warn "no unit tests"
5
- def abbreviate_table_name table_name
6
- table_name_without_schema = table_name.to_s.split(".").last
7
- if table_name_without_schema.nil?
8
- raise "no table name provided"
9
- end
10
- table_name_without_schema.split("_").map { |v| v[0..2] }.join("_")
11
- end
12
- end
13
- end