ridgepole 3.2.2 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa8b60187f54d3f6f510aae6326606c4d0885c3867cc48c6b51d27fd5ac1c5e1
4
- data.tar.gz: 5c52635dff367490eeb5ebda435ea26e4c90f784ef4036c21fb6d58865b93674
3
+ metadata.gz: 1a307f88c8f4187e3ec20de74f563caa0041e66749b0c2bf0345724a2a15103b
4
+ data.tar.gz: b74fc6cae628ac13466fd7dde31679d518f3bcc963bb7dd5877c193720bebf25
5
5
  SHA512:
6
- metadata.gz: 54c4b813601a1bc68891456a7d95ab41641dc63270ca22b0652f06d6757d49b6740a6c0738cc3f5f28c69c5d80c22bd2ecb0b7e7d7de12e6c321f591b95db6cd
7
- data.tar.gz: df2418e5c2bb8ebfe5759c04d3656e524f3b94e995ba24c67f6e74629bdce00667c324d0265433a7333b335ab9245b133c5212a5f0dc282a57692bb6c83b41cf
6
+ metadata.gz: 9b6d880d3b5f91ab5947dd416180c097df2ea99c566df051195357898ee457dbcc35a724467e43b23620d8fc62b1dba7a44460d71535ad7977f1f851a616f08b
7
+ data.tar.gz: 37b2b51fbbf5aadb34fd85d1526b30ddc550bbd85467e3183148f8f8376caf78c0b25f62ed7a32585c6f03caddae73a6e8b8dcbeb762058b609fc382b971bec9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## 3.2
4
4
 
5
+ ### 3.2.3 (2026/08/01)
6
+
7
+ - Emit `validate_constraint` when DB is NOT VALID and DSL implies validated. [pull#718](https://github.com/ridgepole/ridgepole/pull/718)
8
+ - Ignore `validate: false` diff when existing constraint lacks `:validate`. [pull#716](https://github.com/ridgepole/ridgepole/pull/716)
9
+
5
10
  ### 3.2.2 (2026/06/14)
6
11
 
7
12
  - Fix constraint removal order when dropping columns. [pull#705](https://github.com/ridgepole/ridgepole/pull/705)
@@ -568,6 +568,10 @@ remove_index(#{table_name.inspect}, #{target})
568
568
  (delta[:add] || {}).each_value do |attrs|
569
569
  append_add_foreign_key(table_name, attrs, post_buf, options)
570
570
  end
571
+
572
+ (delta[:validate] || {}).each_value do |attrs|
573
+ append_validate_foreign_key(table_name, attrs, post_buf)
574
+ end
571
575
  end
572
576
 
573
577
  def append_add_foreign_key(table_name, attrs, buf, _options)
@@ -594,6 +598,21 @@ remove_foreign_key(#{table_name.inspect}, #{target})
594
598
  RUBY
595
599
  end
596
600
 
601
+ def append_validate_foreign_key(table_name, attrs, buf)
602
+ attrs_options = attrs[:options] || {}
603
+ fk_name = attrs_options[:name]
604
+
605
+ target = if fk_name
606
+ "name: #{fk_name.inspect}"
607
+ else
608
+ attrs.fetch(:to_table).inspect
609
+ end
610
+
611
+ buf.puts(<<-RUBY)
612
+ validate_foreign_key(#{table_name.inspect}, #{target})
613
+ RUBY
614
+ end
615
+
597
616
  def append_change_check_constraints(table_name, delta, pre_buf, post_buf)
598
617
  (delta[:delete] || {}).each_value do |attrs|
599
618
  append_remove_check_constraint(table_name, attrs, pre_buf)
@@ -602,6 +621,10 @@ remove_foreign_key(#{table_name.inspect}, #{target})
602
621
  (delta[:add] || {}).each_value do |attrs|
603
622
  append_add_check_constraint(table_name, attrs, post_buf)
604
623
  end
624
+
625
+ (delta[:validate] || {}).each_value do |attrs|
626
+ append_validate_check_constraint(table_name, attrs, post_buf)
627
+ end
605
628
  end
606
629
 
607
630
  def append_add_check_constraint(table_name, attrs, buf, force_bulk_change = false)
@@ -628,6 +651,15 @@ remove_check_constraint(#{table_name.inspect}, #{expression.inspect}, **#{attrs_
628
651
  RUBY
629
652
  end
630
653
 
654
+ def append_validate_check_constraint(table_name, attrs, buf)
655
+ attrs_options = attrs[:options] || {}
656
+ name = attrs_options[:name]
657
+
658
+ buf.puts(<<-RUBY)
659
+ validate_check_constraint(#{table_name.inspect}, name: #{name.inspect})
660
+ RUBY
661
+ end
662
+
631
663
  def append_change_exclusion_constraints(table_name, delta, pre_buf, post_buf)
632
664
  (delta[:delete] || {}).each_value do |attrs|
633
665
  append_remove_exclusion_constraint(table_name, attrs, pre_buf)
@@ -524,13 +524,18 @@ module Ridgepole
524
524
  next if ignore_fk
525
525
 
526
526
  if from_attrs
527
- if from_attrs != to_attrs
528
- foreign_keys_delta[:add] ||= {}
529
- foreign_keys_delta[:add][foreign_key_name_or_tables] = to_attrs
527
+ if from_attrs != to_attrs && !ignorable_validate_diff?(from_attrs, to_attrs)
528
+ if validate_only_diff?(from_attrs, to_attrs)
529
+ foreign_keys_delta[:validate] ||= {}
530
+ foreign_keys_delta[:validate][foreign_key_name_or_tables] = to_attrs
531
+ else
532
+ foreign_keys_delta[:add] ||= {}
533
+ foreign_keys_delta[:add][foreign_key_name_or_tables] = to_attrs
530
534
 
531
- unless options[:merge]
532
- foreign_keys_delta[:delete] ||= {}
533
- foreign_keys_delta[:delete][foreign_key_name_or_tables] = from_attrs
535
+ unless options[:merge]
536
+ foreign_keys_delta[:delete] ||= {}
537
+ foreign_keys_delta[:delete][foreign_key_name_or_tables] = from_attrs
538
+ end
534
539
  end
535
540
  end
536
541
  else
@@ -558,12 +563,19 @@ module Ridgepole
558
563
  from_attrs = from.delete(name)
559
564
 
560
565
  if from_attrs
561
- if normalize_check_constraint(from_attrs) != normalize_check_constraint(to_attrs)
562
- check_constraints_delta[:add] ||= {}
563
- check_constraints_delta[:add][name] = to_attrs
566
+ from_normalized = normalize_check_constraint(from_attrs)
567
+ to_normalized = normalize_check_constraint(to_attrs)
568
+ if from_normalized != to_normalized && !ignorable_validate_diff?(from_normalized, to_normalized)
569
+ if validate_only_diff?(from_normalized, to_normalized)
570
+ check_constraints_delta[:validate] ||= {}
571
+ check_constraints_delta[:validate][name] = to_attrs
572
+ else
573
+ check_constraints_delta[:add] ||= {}
574
+ check_constraints_delta[:add][name] = to_attrs
564
575
 
565
- check_constraints_delta[:delete] ||= {}
566
- check_constraints_delta[:delete][name] = from_attrs
576
+ check_constraints_delta[:delete] ||= {}
577
+ check_constraints_delta[:delete][name] = from_attrs
578
+ end
567
579
  end
568
580
  else
569
581
  check_constraints_delta[:add] ||= {}
@@ -587,6 +599,33 @@ module Ridgepole
587
599
  attr
588
600
  end
589
601
 
602
+ # 'validate: false' (NOT VALID) is a strategy for ALTER TABLE ADD CONSTRAINT to avoid
603
+ # ACCESS EXCLUSIVE lock on large tables. NOT VALID state itself is persisted by the DB,
604
+ # but PostgreSQL ignores NOT VALID for constraints created inline within CREATE TABLE, so
605
+ # whether the resulting constraint is NOT VALID depends on how it was created. Restoring
606
+ # NOT VALID via DROP + ADD has no benefit, so ignore the diff when the DB dump lacks
607
+ # :validate and the DSL specifies validate: false.
608
+ def ignorable_validate_diff?(from_attrs, to_attrs)
609
+ from_options = from_attrs[:options] || {}
610
+ to_options = to_attrs[:options] || {}
611
+ return false unless to_options[:validate] == false && !from_options.key?(:validate)
612
+
613
+ from_attrs == to_attrs.merge(options: to_options.except(:validate))
614
+ end
615
+
616
+ # Reverse of ignorable_validate_diff?: DB has a NOT VALID constraint (validate: false)
617
+ # and the DSL implies validated (:validate missing or true). Emit VALIDATE CONSTRAINT
618
+ # instead of DROP + re-ADD so the full-table scan runs under SHARE UPDATE EXCLUSIVE
619
+ # (concurrent DML allowed) rather than ACCESS EXCLUSIVE lock.
620
+ def validate_only_diff?(from_attrs, to_attrs)
621
+ from_options = from_attrs[:options] || {}
622
+ to_options = to_attrs[:options] || {}
623
+ return false unless from_options[:validate] == false && to_options[:validate] != false
624
+
625
+ from_attrs.merge(options: from_options.except(:validate)) ==
626
+ to_attrs.merge(options: to_options.except(:validate))
627
+ end
628
+
590
629
  def scan_exclusion_constraints_change(from, to, table_delta)
591
630
  from = (from || {}).dup
592
631
  to = (to || {}).dup
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ridgepole
4
- VERSION = '3.2.2'
4
+ VERSION = '3.2.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -245,14 +245,14 @@ dependencies:
245
245
  requirements:
246
246
  - - '='
247
247
  - !ruby/object:Gem::Version
248
- version: 1.87.0
248
+ version: 1.88.2
249
249
  type: :development
250
250
  prerelease: false
251
251
  version_requirements: !ruby/object:Gem::Requirement
252
252
  requirements:
253
253
  - - '='
254
254
  - !ruby/object:Gem::Version
255
- version: 1.87.0
255
+ version: 1.88.2
256
256
  - !ruby/object:Gem::Dependency
257
257
  name: rubocop-rake
258
258
  requirement: !ruby/object:Gem::Requirement