ridgepole 3.1.4 → 3.2.0.beta

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: 3784ad1d842d1d94b1990eada126a7e089be6b7be6f1d764baf8d0f9e78f9dc1
4
- data.tar.gz: f69dc5c28eac0444853c39bf46e0a64f3e6acfd7ced84d46485993594f56a3b4
3
+ metadata.gz: 3779bc8749c7a1bbfff8cffe381af079bdeaa0caaa6b7f9058990c0089a9052b
4
+ data.tar.gz: a71190beaa092b5167020190ffc76405712116d8c0f9cab99c286cdf2e49824f
5
5
  SHA512:
6
- metadata.gz: 3c61e60599c78c740e21f36e087e8d9931e01ed801c05a64e78b11dcca30f872acbe34df427fe27da44734e07a1bbb2f408fb6e2bec6e037224a33cdb6455cd5
7
- data.tar.gz: fd7fabfea47e6d71217e0b38463d3049c58864d02f5f7e094b98c533802b54dfb55fd2932af603a219c846830e73c3e6d6d408917f703f84a65377f486f5ec44
6
+ metadata.gz: 2e61dd23b379debefeeaafdfbc9b7f9381a3b8e8cf3fc07c893038b1231a4f401dd440f35bd19802d0829a643b0f40d5363b2f3e934cafadfa2aa9766cd7cdcd
7
+ data.tar.gz: 5ca8c6ced24e4d9276da3cef89278497e177b11af4c3a5b468401d7773dd8559c6de2f6178178f9db5110c17b3dd40b30610459dae19de6dfb9113ad63c92f79
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## 3.0
4
4
 
5
+ ### 3.2.0.beta (2026/03/22)
6
+
7
+ - Use `udiff` instead of `diffy`. [pull#657](https://github.com/ridgepole/ridgepole/pull/657)
8
+
9
+ ### 3.1.5 (2026/03/21)
10
+
11
+ - Fix for renaming references column. [pull#652](https://github.com/ridgepole/ridgepole/pull/652)
12
+ - Fix for creating table with non-PK auto_increment column. [pull#650](https://github.com/ridgepole/ridgepole/pull/650)
13
+
5
14
  ### 3.1.4 (2026/03/20)
6
15
 
7
16
  - Fix for errors when changing generated columns. [pull#642](https://github.com/ridgepole/ridgepole/pull/642) [pull#646](https://github.com/ridgepole/ridgepole/pull/646)
data/README.md CHANGED
@@ -15,6 +15,8 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
15
15
  > If you do not want to sort the columns, use `--disable-sort-columns` option.
16
16
 
17
17
  > [!note]
18
+ > * ridgepole v3.2.0
19
+ > * Use `udiff` instead of `diffy` (cf. https://github.com/ridgepole/ridgepole/pull/657)
18
20
  > * ridgepole v3.1.0
19
21
  > * Support Rails 8.1 (cf. https://github.com/ridgepole/ridgepole/pull/589)
20
22
  > * ridgepole v3.0.0
@@ -243,10 +243,18 @@ create_table(#{table_name.inspect}, #{inspect_options_include_default_proc(optio
243
243
  RUBY
244
244
  end
245
245
 
246
- if @options[:create_table_with_index] && !indices.empty?
247
- indices.each do |index_name, index_attrs|
248
- append_add_index(table_name, index_name, index_attrs, buf, true)
249
- end
246
+ # Partition indices: indices referencing auto_increment columns must be
247
+ # inside CREATE TABLE on MySQL to avoid "must be defined as a key" error.
248
+ # cf. https://github.com/ridgepole/ridgepole/issues/494
249
+ if @options[:create_table_with_index]
250
+ indices_in_create = indices
251
+ indices_after_create = {}
252
+ else
253
+ indices_in_create, indices_after_create = partition_indices_for_create(definition, indices)
254
+ end
255
+
256
+ indices_in_create.each do |index_name, index_attrs|
257
+ append_add_index(table_name, index_name, index_attrs, buf, true)
250
258
  end
251
259
 
252
260
  unless (check_constraints = attrs[:check_constraints] || {}).empty?
@@ -271,9 +279,9 @@ create_table(#{table_name.inspect}, #{inspect_options_include_default_proc(optio
271
279
  end
272
280
  RUBY
273
281
 
274
- if !@options[:create_table_with_index] && !indices.empty?
282
+ unless indices_after_create.empty?
275
283
  append_change_table(table_name, buf) do
276
- indices.each do |index_name, index_attrs|
284
+ indices_after_create.each do |index_name, index_attrs|
277
285
  append_add_index(table_name, index_name, index_attrs, buf)
278
286
  end
279
287
  end
@@ -289,6 +297,30 @@ end
289
297
  post_buf_for_fk.puts
290
298
  end
291
299
 
300
+ def partition_indices_for_create(definition, indices)
301
+ return [{}, indices] unless Ridgepole::ConnectionAdapters.mysql?
302
+
303
+ auto_increment_columns = definition.select do |_col_name, col_attrs|
304
+ col_attrs.dig(:options, :auto_increment)
305
+ end.keys
306
+
307
+ return [{}, indices] if auto_increment_columns.empty?
308
+
309
+ in_create = {}
310
+ after_create = {}
311
+
312
+ indices.each do |idx_name, idx_attrs|
313
+ columns = Array(idx_attrs[:column_name])
314
+ if (columns & auto_increment_columns).any?
315
+ in_create[idx_name] = idx_attrs
316
+ else
317
+ after_create[idx_name] = idx_attrs
318
+ end
319
+ end
320
+
321
+ [in_create, after_create]
322
+ end
323
+
292
324
  def append_rename_table(to_table_name, from_table_name, buf)
293
325
  buf.puts(<<-RUBY)
294
326
  rename_table(#{from_table_name.inspect}, #{to_table_name.inspect})
@@ -103,6 +103,7 @@ module Ridgepole
103
103
 
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
+ apply_column_renames_to_indices(from[:indices], table_delta.dig(:definition, :rename))
106
107
  scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta, from[:options], to[:options])
107
108
  scan_foreign_keys_change(from[:foreign_keys], to[:foreign_keys], table_delta, @options)
108
109
  scan_check_constraints_change(from[:check_constraints], to[:check_constraints], table_delta)
@@ -342,6 +343,19 @@ module Ridgepole
342
343
  end
343
344
  end
344
345
 
346
+ def apply_column_renames_to_indices(indices, renames)
347
+ return unless indices && renames
348
+
349
+ # renames: { new_column_name => old_column_name }
350
+ rename_map = renames.invert # { old_column_name => new_column_name }
351
+
352
+ indices.each_value do |attrs|
353
+ next unless attrs[:column_name].is_a?(Array)
354
+
355
+ attrs[:column_name] = attrs[:column_name].map { |col| rename_map[col] || col }
356
+ end
357
+ end
358
+
345
359
  def scan_indices_change(from, to, to_columns, table_delta, _from_table_options, to_table_options)
346
360
  from = (from || {}).dup
347
361
  to = (to || {}).dup
@@ -683,13 +697,12 @@ module Ridgepole
683
697
  obj1 = Ridgepole::Ext::PpSortHash.extend_if_hash(obj1)
684
698
  obj2 = Ridgepole::Ext::PpSortHash.extend_if_hash(obj2)
685
699
 
686
- diffy = Diffy::Diff.new(
700
+ diff = Udiff::Diff.new(
687
701
  obj1.pretty_inspect,
688
- obj2.pretty_inspect,
689
- diff: '-u'
702
+ obj2.pretty_inspect
690
703
  )
691
704
 
692
- diffy.to_s(@options[:color] ? :color : :text).gsub(/\s+\z/m, '')
705
+ diff.to_s(@options[:color] ? :color : :text).gsub(/\s+\z/m, '')
693
706
  end
694
707
 
695
708
  def collect_relation_info!(table_name, table_attr, relation_info)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ridgepole
4
- VERSION = '3.1.4'
4
+ VERSION = '3.2.0.beta'
5
5
  end
data/lib/ridgepole.rb CHANGED
@@ -11,7 +11,7 @@ require 'active_record'
11
11
  require 'active_support'
12
12
  require 'active_support/core_ext'
13
13
 
14
- require 'diffy'
14
+ require 'udiff'
15
15
 
16
16
  module Ridgepole; end
17
17
 
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.1.4
4
+ version: 3.2.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -30,7 +30,7 @@ dependencies:
30
30
  - !ruby/object:Gem::Version
31
31
  version: '8.3'
32
32
  - !ruby/object:Gem::Dependency
33
- name: diffy
33
+ name: logger
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ">="
@@ -44,19 +44,19 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: logger
47
+ name: udiff
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: '0'
52
+ version: 0.2.0
53
53
  type: :runtime
54
54
  prerelease: false
55
55
  version_requirements: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '0'
59
+ version: 0.2.0
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: appraisal
62
62
  requirement: !ruby/object:Gem::Requirement