ridgepole 3.2.0 → 3.2.2
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 +8 -0
- data/README.md +8 -2
- data/lib/ridgepole/delta.rb +28 -28
- data/lib/ridgepole/diff.rb +14 -3
- data/lib/ridgepole/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aa8b60187f54d3f6f510aae6326606c4d0885c3867cc48c6b51d27fd5ac1c5e1
|
|
4
|
+
data.tar.gz: 5c52635dff367490eeb5ebda435ea26e4c90f784ef4036c21fb6d58865b93674
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54c4b813601a1bc68891456a7d95ab41641dc63270ca22b0652f06d6757d49b6740a6c0738cc3f5f28c69c5d80c22bd2ecb0b7e7d7de12e6c321f591b95db6cd
|
|
7
|
+
data.tar.gz: df2418e5c2bb8ebfe5759c04d3656e524f3b94e995ba24c67f6e74629bdce00667c324d0265433a7333b335ab9245b133c5212a5f0dc282a57692bb6c83b41cf
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## 3.2
|
|
4
4
|
|
|
5
|
+
### 3.2.2 (2026/06/14)
|
|
6
|
+
|
|
7
|
+
- Fix constraint removal order when dropping columns. [pull#705](https://github.com/ridgepole/ridgepole/pull/705)
|
|
8
|
+
|
|
9
|
+
### 3.2.1 (2026/05/04)
|
|
10
|
+
|
|
11
|
+
- Warn when an anonymous index ambiguously matches multiple DB indexes. [pull#692](https://github.com/ridgepole/ridgepole/pull/692)
|
|
12
|
+
|
|
5
13
|
### 3.2.0 (2026/03/28)
|
|
6
14
|
|
|
7
15
|
- Fix spurious diff for `timestamp`/`datetime` with `precision: 6` on MySQL. [pull#665](https://github.com/ridgepole/ridgepole/pull/665)
|
data/README.md
CHANGED
|
@@ -9,6 +9,12 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
|
9
9
|
[](https://github.com/ridgepole/ridgepole/actions/workflows/test.yml)
|
|
10
10
|
[](https://codecov.io/gh/ridgepole/ridgepole)
|
|
11
11
|
|
|
12
|
+
> [!TIP]
|
|
13
|
+
> Also developing similar declarative schema tools — single Go binary, plain SQL as the schema definition:
|
|
14
|
+
>
|
|
15
|
+
> * [pistachio](https://github.com/winebarrel/pistachio): for PostgreSQL
|
|
16
|
+
> * [myschema](https://github.com/winebarrel/myschema): for MySQL
|
|
17
|
+
|
|
12
18
|
> [!warning]
|
|
13
19
|
> The order of columns when exporting has changed in Rails 8.1. https://github.com/rails/rails/pull/53281
|
|
14
20
|
>
|
|
@@ -315,11 +321,11 @@ EOS
|
|
|
315
321
|
|
|
316
322
|
execute("CREATE OR REPLACE VIEW `active_users` AS #{view_select}") do |c|
|
|
317
323
|
definition = c.raw_connection.query(<<-SQL).first&.first
|
|
318
|
-
SELECT
|
|
324
|
+
SELECT VIEW_DEFINITION FROM information_schema.views
|
|
319
325
|
WHERE TABLE_SCHEMA = 'mydb'
|
|
320
326
|
AND TABLE_NAME = 'active_users';
|
|
321
327
|
SQL
|
|
322
|
-
definition != view_select
|
|
328
|
+
definition&.strip != view_select
|
|
323
329
|
end
|
|
324
330
|
```
|
|
325
331
|
|
data/lib/ridgepole/delta.rb
CHANGED
|
@@ -31,11 +31,11 @@ module Ridgepole
|
|
|
31
31
|
|
|
32
32
|
def script
|
|
33
33
|
buf = StringIO.new
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
pre_buf = StringIO.new
|
|
35
|
+
post_buf = StringIO.new
|
|
36
36
|
|
|
37
37
|
(@delta[:add] || {}).each do |table_name, attrs|
|
|
38
|
-
append_create_table(table_name, attrs, buf,
|
|
38
|
+
append_create_table(table_name, attrs, buf, post_buf)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
(@delta[:rename] || {}).each do |table_name, attrs|
|
|
@@ -43,7 +43,7 @@ module Ridgepole
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
(@delta[:change] || {}).each do |table_name, attrs|
|
|
46
|
-
append_change(table_name, attrs, buf,
|
|
46
|
+
append_change(table_name, attrs, buf, pre_buf, post_buf)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
(@delta[:delete] || {}).each do |table_name, attrs|
|
|
@@ -51,9 +51,9 @@ module Ridgepole
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
[
|
|
54
|
-
|
|
54
|
+
pre_buf,
|
|
55
55
|
buf,
|
|
56
|
-
|
|
56
|
+
post_buf
|
|
57
57
|
].map { |b| b.string.strip }.join("\n\n").strip
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -221,7 +221,7 @@ module Ridgepole
|
|
|
221
221
|
end
|
|
222
222
|
end
|
|
223
223
|
|
|
224
|
-
def append_create_table(table_name, attrs, buf,
|
|
224
|
+
def append_create_table(table_name, attrs, buf, post_buf)
|
|
225
225
|
options = attrs[:options] || {}
|
|
226
226
|
definition = attrs[:definition] || {}
|
|
227
227
|
indices = attrs[:indices] || {}
|
|
@@ -289,12 +289,12 @@ end
|
|
|
289
289
|
|
|
290
290
|
unless (foreign_keys = attrs[:foreign_keys] || {}).empty?
|
|
291
291
|
foreign_keys.each_value do |foreign_key_attrs|
|
|
292
|
-
append_add_foreign_key(table_name, foreign_key_attrs,
|
|
292
|
+
append_add_foreign_key(table_name, foreign_key_attrs, post_buf, @options)
|
|
293
293
|
end
|
|
294
294
|
end
|
|
295
295
|
|
|
296
296
|
buf.puts
|
|
297
|
-
|
|
297
|
+
post_buf.puts
|
|
298
298
|
end
|
|
299
299
|
|
|
300
300
|
def partition_indices_for_create(definition, indices)
|
|
@@ -370,7 +370,7 @@ change_table_comment(#{table_name.inspect}, #{table_comment.inspect})
|
|
|
370
370
|
end
|
|
371
371
|
end
|
|
372
372
|
|
|
373
|
-
def append_change(table_name, attrs, buf,
|
|
373
|
+
def append_change(table_name, attrs, buf, pre_buf, post_buf)
|
|
374
374
|
definition = attrs[:definition] || {}
|
|
375
375
|
primary_key_definition = attrs[:primary_key_definition] || {}
|
|
376
376
|
indices = attrs[:indices] || {}
|
|
@@ -393,10 +393,10 @@ change_table_comment(#{table_name.inspect}, #{table_comment.inspect})
|
|
|
393
393
|
end
|
|
394
394
|
end
|
|
395
395
|
|
|
396
|
-
append_change_foreign_keys(table_name, foreign_keys,
|
|
397
|
-
append_change_check_constraints(table_name, check_constraints,
|
|
398
|
-
append_change_exclusion_constraints(table_name, exclusion_constraints,
|
|
399
|
-
append_change_unique_constraints(table_name, unique_constraints,
|
|
396
|
+
append_change_foreign_keys(table_name, foreign_keys, pre_buf, post_buf, @options) unless foreign_keys.empty?
|
|
397
|
+
append_change_check_constraints(table_name, check_constraints, pre_buf, post_buf) unless check_constraints.empty?
|
|
398
|
+
append_change_exclusion_constraints(table_name, exclusion_constraints, pre_buf, post_buf) unless exclusion_constraints.empty?
|
|
399
|
+
append_change_unique_constraints(table_name, unique_constraints, pre_buf, post_buf) unless unique_constraints.empty?
|
|
400
400
|
|
|
401
401
|
if table_options || table_charset || table_collation
|
|
402
402
|
append_change_table_raw_options(table_name, table_options, table_charset, table_collation,
|
|
@@ -407,8 +407,8 @@ change_table_comment(#{table_name.inspect}, #{table_comment.inspect})
|
|
|
407
407
|
append_change_column_comments(table_name, column_comments, buf) unless column_comments.empty?
|
|
408
408
|
|
|
409
409
|
buf.puts
|
|
410
|
-
|
|
411
|
-
|
|
410
|
+
pre_buf.puts
|
|
411
|
+
post_buf.puts
|
|
412
412
|
end
|
|
413
413
|
|
|
414
414
|
def append_change_column_comments(table_name, column_comments, buf)
|
|
@@ -560,13 +560,13 @@ remove_index(#{table_name.inspect}, #{target})
|
|
|
560
560
|
end
|
|
561
561
|
end
|
|
562
562
|
|
|
563
|
-
def append_change_foreign_keys(table_name, delta,
|
|
563
|
+
def append_change_foreign_keys(table_name, delta, pre_buf, post_buf, options)
|
|
564
564
|
(delta[:delete] || {}).each_value do |attrs|
|
|
565
|
-
append_remove_foreign_key(table_name, attrs,
|
|
565
|
+
append_remove_foreign_key(table_name, attrs, pre_buf, options)
|
|
566
566
|
end
|
|
567
567
|
|
|
568
568
|
(delta[:add] || {}).each_value do |attrs|
|
|
569
|
-
append_add_foreign_key(table_name, attrs,
|
|
569
|
+
append_add_foreign_key(table_name, attrs, post_buf, options)
|
|
570
570
|
end
|
|
571
571
|
end
|
|
572
572
|
|
|
@@ -594,13 +594,13 @@ remove_foreign_key(#{table_name.inspect}, #{target})
|
|
|
594
594
|
RUBY
|
|
595
595
|
end
|
|
596
596
|
|
|
597
|
-
def append_change_check_constraints(table_name, delta,
|
|
597
|
+
def append_change_check_constraints(table_name, delta, pre_buf, post_buf)
|
|
598
598
|
(delta[:delete] || {}).each_value do |attrs|
|
|
599
|
-
append_remove_check_constraint(table_name, attrs,
|
|
599
|
+
append_remove_check_constraint(table_name, attrs, pre_buf)
|
|
600
600
|
end
|
|
601
601
|
|
|
602
602
|
(delta[:add] || {}).each_value do |attrs|
|
|
603
|
-
append_add_check_constraint(table_name, attrs,
|
|
603
|
+
append_add_check_constraint(table_name, attrs, post_buf)
|
|
604
604
|
end
|
|
605
605
|
end
|
|
606
606
|
|
|
@@ -628,13 +628,13 @@ remove_check_constraint(#{table_name.inspect}, #{expression.inspect}, **#{attrs_
|
|
|
628
628
|
RUBY
|
|
629
629
|
end
|
|
630
630
|
|
|
631
|
-
def append_change_exclusion_constraints(table_name, delta,
|
|
631
|
+
def append_change_exclusion_constraints(table_name, delta, pre_buf, post_buf)
|
|
632
632
|
(delta[:delete] || {}).each_value do |attrs|
|
|
633
|
-
append_remove_exclusion_constraint(table_name, attrs,
|
|
633
|
+
append_remove_exclusion_constraint(table_name, attrs, pre_buf)
|
|
634
634
|
end
|
|
635
635
|
|
|
636
636
|
(delta[:add] || {}).each_value do |attrs|
|
|
637
|
-
append_add_exclusion_constraint(table_name, attrs,
|
|
637
|
+
append_add_exclusion_constraint(table_name, attrs, post_buf)
|
|
638
638
|
end
|
|
639
639
|
end
|
|
640
640
|
|
|
@@ -662,13 +662,13 @@ remove_exclusion_constraint(#{table_name.inspect}, #{expression.inspect}, **#{at
|
|
|
662
662
|
RUBY
|
|
663
663
|
end
|
|
664
664
|
|
|
665
|
-
def append_change_unique_constraints(table_name, delta,
|
|
665
|
+
def append_change_unique_constraints(table_name, delta, pre_buf, post_buf)
|
|
666
666
|
(delta[:delete] || {}).each_value do |attrs|
|
|
667
|
-
append_remove_unique_constraint(table_name, attrs,
|
|
667
|
+
append_remove_unique_constraint(table_name, attrs, pre_buf)
|
|
668
668
|
end
|
|
669
669
|
|
|
670
670
|
(delta[:add] || {}).each_value do |attrs|
|
|
671
|
-
append_add_unique_constraint(table_name, attrs,
|
|
671
|
+
append_add_unique_constraint(table_name, attrs, post_buf)
|
|
672
672
|
end
|
|
673
673
|
end
|
|
674
674
|
|
data/lib/ridgepole/diff.rb
CHANGED
|
@@ -104,7 +104,7 @@ module Ridgepole
|
|
|
104
104
|
scan_options_change(table_name, from[:options], to[:options], table_delta)
|
|
105
105
|
scan_definition_change(from[:definition], to[:definition], from[:indices], table_name, from[:options], table_delta)
|
|
106
106
|
apply_column_renames_to_indices(from[:indices], table_delta.dig(:definition, :rename))
|
|
107
|
-
scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta, from[:options], to[:options])
|
|
107
|
+
scan_indices_change(table_name, from[:indices], to[:indices], to[:definition], table_delta, from[:options], to[:options])
|
|
108
108
|
scan_foreign_keys_change(from[:foreign_keys], to[:foreign_keys], table_delta, @options)
|
|
109
109
|
scan_check_constraints_change(from[:check_constraints], to[:check_constraints], table_delta)
|
|
110
110
|
scan_exclusion_constraints_change(from[:exclusion_constraints], to[:exclusion_constraints], table_delta)
|
|
@@ -356,7 +356,7 @@ module Ridgepole
|
|
|
356
356
|
end
|
|
357
357
|
end
|
|
358
358
|
|
|
359
|
-
def scan_indices_change(from, to, to_columns, table_delta, _from_table_options, to_table_options)
|
|
359
|
+
def scan_indices_change(table_name, from, to, to_columns, table_delta, _from_table_options, to_table_options)
|
|
360
360
|
from = (from || {}).dup
|
|
361
361
|
to = (to || {}).dup
|
|
362
362
|
indices_delta = {}
|
|
@@ -365,7 +365,18 @@ module Ridgepole
|
|
|
365
365
|
ignore_index = to_attrs.fetch(:options, {}).delete(:ignore)
|
|
366
366
|
|
|
367
367
|
if index_name.is_a?(Array)
|
|
368
|
-
|
|
368
|
+
matching = from.select { |_name, attrs| attrs[:column_name] == index_name }
|
|
369
|
+
|
|
370
|
+
if matching.size > 1 && !ignore_index
|
|
371
|
+
@logger.warn(
|
|
372
|
+
"[WARNING] Multiple existing indexes on `#{table_name}` match column #{index_name.inspect}: " \
|
|
373
|
+
"#{matching.keys.map(&:inspect).join(', ')}. " \
|
|
374
|
+
'The choice of which index to keep depends on iteration order; ' \
|
|
375
|
+
'specify `name:` explicitly to disambiguate.'
|
|
376
|
+
)
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
from_index_name, from_attrs = matching.first
|
|
369
380
|
|
|
370
381
|
if from_attrs
|
|
371
382
|
from.delete(from_index_name)
|
data/lib/ridgepole/version.rb
CHANGED
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.
|
|
4
|
+
version: 3.2.2
|
|
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.
|
|
248
|
+
version: 1.87.0
|
|
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.
|
|
255
|
+
version: 1.87.0
|
|
256
256
|
- !ruby/object:Gem::Dependency
|
|
257
257
|
name: rubocop-rake
|
|
258
258
|
requirement: !ruby/object:Gem::Requirement
|