ridgepole 3.1.2 → 3.1.4
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 +9 -0
- data/README.md +29 -4
- data/bin/ridgepole +6 -1
- data/lib/ridgepole/client.rb +1 -1
- data/lib/ridgepole/delta.rb +9 -2
- data/lib/ridgepole/diff.rb +5 -3
- data/lib/ridgepole/dsl_parser/context.rb +1 -1
- data/lib/ridgepole/execute_expander.rb +34 -8
- data/lib/ridgepole/version.rb +1 -1
- metadata +50 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3784ad1d842d1d94b1990eada126a7e089be6b7be6f1d764baf8d0f9e78f9dc1
|
|
4
|
+
data.tar.gz: f69dc5c28eac0444853c39bf46e0a64f3e6acfd7ced84d46485993594f56a3b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c61e60599c78c740e21f36e087e8d9931e01ed801c05a64e78b11dcca30f872acbe34df427fe27da44734e07a1bbb2f408fb6e2bec6e037224a33cdb6455cd5
|
|
7
|
+
data.tar.gz: fd7fabfea47e6d71217e0b38463d3049c58864d02f5f7e094b98c533802b54dfb55fd2932af603a219c846830e73c3e6d6d408917f703f84a65377f486f5ec44
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## 3.0
|
|
4
4
|
|
|
5
|
+
### 3.1.4 (2026/03/20)
|
|
6
|
+
|
|
7
|
+
- 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)
|
|
8
|
+
- Fix for changes to `create_table` in ActiveRecord 8.2. [pull#645](https://github.com/ridgepole/ridgepole/pull/645)
|
|
9
|
+
|
|
10
|
+
### 3.1.3 (2026/01/29)
|
|
11
|
+
|
|
12
|
+
- Show `COMMENT` SQL in dry-run. [pull#632](https://github.com/ridgepole/ridgepole/pull/632)
|
|
13
|
+
|
|
5
14
|
### 3.1.2 (2025/11/03)
|
|
6
15
|
|
|
7
16
|
- Normalize foreign key columns. [pull#607](https://github.com/ridgepole/ridgepole/pull/607)
|
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
|
7
7
|
|
|
8
8
|
[](https://badge.fury.io/rb/ridgepole)
|
|
9
9
|
[](https://github.com/ridgepole/ridgepole/actions/workflows/test.yml)
|
|
10
|
-
[](https://codecov.io/gh/ridgepole/ridgepole)
|
|
11
11
|
|
|
12
12
|
> [!warning]
|
|
13
13
|
> The order of columns when exporting has changed in Rails 8.1. https://github.com/rails/rails/pull/53281
|
|
@@ -211,6 +211,31 @@ add_index "child", ["parent_id"], name: "par_ind", using: :btree
|
|
|
211
211
|
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
|
212
212
|
```
|
|
213
213
|
|
|
214
|
+
## CHECK Constraint
|
|
215
|
+
|
|
216
|
+
```ruby
|
|
217
|
+
create_table "products", force: :cascade do |t|
|
|
218
|
+
t.string "name", null: false
|
|
219
|
+
t.decimal "price", precision: 10, scale: 2
|
|
220
|
+
t.integer "quantity"
|
|
221
|
+
|
|
222
|
+
t.check_constraint "price > 0", name: "price_check"
|
|
223
|
+
t.check_constraint "quantity >= 0", name: "quantity_check"
|
|
224
|
+
end
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
> [!important]
|
|
228
|
+
> **Matching Schemafile to Database Output**
|
|
229
|
+
>
|
|
230
|
+
> CHECK constraint expressions may be formatted differently by your database when exported. For example:
|
|
231
|
+
> - DSL: `"(price > 0)"`
|
|
232
|
+
> - Database export: `` "`price` > 0" `` (MySQL) or `"((price > 0))"` (PostgreSQL)
|
|
233
|
+
>
|
|
234
|
+
> To avoid unnecessary migrations where constraints are dropped and recreated:
|
|
235
|
+
> Please modify your Schemafile to match exactly what the SchemaDumper outputs. This approach maintains simplicity and prevents migration issues instead of maintaining complex normalization logic in Ridgepole.
|
|
236
|
+
>
|
|
237
|
+
> Run `ridgepole --export` to see the exact format your database uses, then update your Schemafile accordingly.
|
|
238
|
+
|
|
214
239
|
## Ignore Column/Index/FK
|
|
215
240
|
|
|
216
241
|
```ruby
|
|
@@ -387,9 +412,9 @@ see https://github.com/ridgepole/ridgepole/issues/568
|
|
|
387
412
|
docker compose up -d
|
|
388
413
|
bundle install
|
|
389
414
|
bundle exec appraisal install
|
|
390
|
-
bundle exec appraisal activerecord-
|
|
391
|
-
# POSTGRESQL=1 bundle exec appraisal activerecord-
|
|
392
|
-
# MYSQL80=1 bundle exec appraisal activerecord-
|
|
415
|
+
bundle exec appraisal activerecord-8.1 rake
|
|
416
|
+
# POSTGRESQL=1 bundle exec appraisal activerecord-8.1 rake
|
|
417
|
+
# MYSQL80=1 bundle exec appraisal activerecord-8.1 rake
|
|
393
418
|
```
|
|
394
419
|
|
|
395
420
|
> [!note]
|
data/bin/ridgepole
CHANGED
|
@@ -187,7 +187,12 @@ begin
|
|
|
187
187
|
client = Ridgepole::Client.new(Ridgepole::Config.load(config, env, spec_name), options) if config
|
|
188
188
|
|
|
189
189
|
ActiveRecord::Base.logger = logger
|
|
190
|
-
|
|
190
|
+
|
|
191
|
+
if ActiveRecord.gem_version < Gem::Version.new('8.2.0.alpha')
|
|
192
|
+
ActiveSupport::LogSubscriber.colorize_logging = options[:color]
|
|
193
|
+
else
|
|
194
|
+
ActiveSupport.colorize_logging = options[:color]
|
|
195
|
+
end
|
|
191
196
|
|
|
192
197
|
case mode
|
|
193
198
|
when :export
|
data/lib/ridgepole/client.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Ridgepole
|
|
|
10
10
|
# XXX: If the required processing in class method?
|
|
11
11
|
@options[:index_removed_drop_column] = true if !@options.key?(:index_removed_drop_column) && (Ridgepole::DefaultsLimit.adapter == :postgresql)
|
|
12
12
|
|
|
13
|
-
Ridgepole::ExecuteExpander.expand_execute(ActiveRecord::Base.connection)
|
|
13
|
+
Ridgepole::ExecuteExpander.expand_execute(ActiveRecord::Base.connection, @options)
|
|
14
14
|
@dumper = Ridgepole::Dumper.new(@options)
|
|
15
15
|
@parser = Ridgepole::DSLParser.new(@options)
|
|
16
16
|
@diff = Ridgepole::Diff.new(@options)
|
data/lib/ridgepole/delta.rb
CHANGED
|
@@ -74,8 +74,8 @@ module Ridgepole
|
|
|
74
74
|
ActiveRecord::Migration.disable_logging = true
|
|
75
75
|
buf = StringIO.new
|
|
76
76
|
|
|
77
|
-
callback = proc do |sql
|
|
78
|
-
buf.puts sql if sql =~ /\A(CREATE|ALTER|DROP|RENAME)\b/i
|
|
77
|
+
callback = proc do |sql|
|
|
78
|
+
buf.puts sql if sql =~ /\A(CREATE|ALTER|DROP|RENAME|COMMENT)\b/i
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
eval_script_block = proc do
|
|
@@ -446,6 +446,13 @@ rename_column(#{table_name.inspect}, #{from_column_name.inspect}, #{to_column_na
|
|
|
446
446
|
# Fix for https://github.com/rails/rails/commit/7f0567b43b73b1bd1a16bfac9cd32fcbf1321b51
|
|
447
447
|
if Ridgepole::ConnectionAdapters.mysql?
|
|
448
448
|
options[:comment] = nil unless options.key?(:comment)
|
|
449
|
+
|
|
450
|
+
# Generated/virtual columns cannot have DEFAULT values in MySQL.
|
|
451
|
+
# cf. https://github.com/ridgepole/ridgepole/issues/482
|
|
452
|
+
if type == :virtual
|
|
453
|
+
options.delete(:default)
|
|
454
|
+
options.delete(:unsigned)
|
|
455
|
+
end
|
|
449
456
|
end
|
|
450
457
|
|
|
451
458
|
if @options[:bulk_change]
|
data/lib/ridgepole/diff.rb
CHANGED
|
@@ -410,15 +410,17 @@ module Ridgepole
|
|
|
410
410
|
|
|
411
411
|
def normalize_column_options!(attrs, primary_key = false)
|
|
412
412
|
opts = attrs[:options]
|
|
413
|
-
opts[:null] = true if !opts.key?(:null) && !primary_key
|
|
413
|
+
opts[:null] = true if !opts.key?(:null) && !primary_key && attrs[:type] != :virtual
|
|
414
414
|
default_limit = Ridgepole::DefaultsLimit.default_limit(attrs[:type], @options)
|
|
415
415
|
opts.delete(:limit) if opts[:limit] == default_limit
|
|
416
416
|
|
|
417
417
|
# XXX: MySQL only?
|
|
418
|
-
|
|
418
|
+
# Generated/virtual columns cannot have DEFAULT values in MySQL.
|
|
419
|
+
# cf. https://github.com/ridgepole/ridgepole/issues/482
|
|
420
|
+
opts[:default] = nil if !opts.key?(:default) && !primary_key && attrs[:type] != :virtual
|
|
419
421
|
|
|
420
422
|
if Ridgepole::ConnectionAdapters.mysql?
|
|
421
|
-
opts[:unsigned] = false
|
|
423
|
+
opts[:unsigned] = false if !opts.key?(:unsigned) && attrs[:type] != :virtual
|
|
422
424
|
|
|
423
425
|
if attrs[:type] == :integer && opts[:limit]
|
|
424
426
|
min = Ridgepole::DefaultsLimit.default_limit(:integer, @options)
|
|
@@ -48,7 +48,7 @@ module Ridgepole
|
|
|
48
48
|
table_name = table_name.to_s
|
|
49
49
|
# Keep column_name for expression index support
|
|
50
50
|
# https://github.com/rails/rails/pull/23393
|
|
51
|
-
column_name = [column_name].flatten.map(&:to_s) unless column_name.is_a?(String) && /\W/ === column_name
|
|
51
|
+
column_name = [column_name].flatten.map(&:to_s) unless column_name.is_a?(String) && /\W/ === column_name
|
|
52
52
|
options[:name] = options[:name].to_s if options[:name]
|
|
53
53
|
@__definition[table_name] ||= {}
|
|
54
54
|
@__definition[table_name][:indices] ||= {}
|
|
@@ -13,19 +13,24 @@ module Ridgepole
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
module ConnectionAdapterExt
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
def execute_expander_internal_execute(sql, &block)
|
|
17
|
+
# Generated/virtual columns cannot have DEFAULT values in MySQL.
|
|
18
|
+
# Rails' change_column always adds DEFAULT from the existing column,
|
|
19
|
+
# so we strip it from the SQL for virtual columns.
|
|
20
|
+
# cf. https://github.com/ridgepole/ridgepole/issues/482
|
|
21
|
+
if Ridgepole::ConnectionAdapters.mysql? && !Ridgepole::ExecuteExpander.options[:bulk_change]
|
|
22
|
+
# NOTE: bulk_change does not support changing MySQL generated columns with `DEFAULT NULL`.
|
|
23
|
+
sql = sql.sub(/\bDEFAULT\s+NULL\z/i, '') if /\AALTER\s+TABLE\b/i.match?(sql) && /\bAS\s*\(/i.match?(sql) && /\bDEFAULT\s+NULL\z/i.match?(sql)
|
|
24
|
+
end
|
|
20
25
|
if Ridgepole::ExecuteExpander.noop
|
|
21
26
|
if (callback = Ridgepole::ExecuteExpander.callback)
|
|
22
27
|
sql = append_alter_extra(sql)
|
|
23
|
-
callback.call(sql
|
|
28
|
+
callback.call(sql)
|
|
24
29
|
end
|
|
25
30
|
|
|
26
31
|
if /\A(SELECT|SHOW)\b/i.match?(sql)
|
|
27
32
|
begin
|
|
28
|
-
|
|
33
|
+
block.call(sql)
|
|
29
34
|
rescue StandardError
|
|
30
35
|
Stub.new
|
|
31
36
|
end
|
|
@@ -34,7 +39,7 @@ module Ridgepole
|
|
|
34
39
|
end
|
|
35
40
|
elsif Ridgepole::ExecuteExpander.use_script
|
|
36
41
|
if /\A(SELECT|SHOW)\b/i.match?(sql)
|
|
37
|
-
|
|
42
|
+
block.call(sql)
|
|
38
43
|
else
|
|
39
44
|
sql = append_alter_extra(sql)
|
|
40
45
|
Ridgepole::ExecuteExpander.sql_executer.execute(sql)
|
|
@@ -42,10 +47,28 @@ module Ridgepole
|
|
|
42
47
|
end
|
|
43
48
|
else
|
|
44
49
|
sql = append_alter_extra(sql)
|
|
50
|
+
block.call(sql)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def execute(*args)
|
|
55
|
+
name = args[1]
|
|
56
|
+
execute_expander_internal_execute(args.fetch(0)) do |sql|
|
|
45
57
|
super(sql, name)
|
|
46
58
|
end
|
|
47
59
|
end
|
|
48
60
|
|
|
61
|
+
def execute_batch(statements, name = nil, **kwargs)
|
|
62
|
+
new_statements = []
|
|
63
|
+
statements.each do |statement|
|
|
64
|
+
execute_expander_internal_execute(statement) do |sql|
|
|
65
|
+
new_statements << sql
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
super(new_statements, name, **kwargs) unless new_statements.empty?
|
|
69
|
+
statements
|
|
70
|
+
end
|
|
71
|
+
|
|
49
72
|
private
|
|
50
73
|
|
|
51
74
|
def append_alter_extra(sql)
|
|
@@ -69,6 +92,7 @@ module Ridgepole
|
|
|
69
92
|
cattr_accessor :use_script, instance_writer: false, instance_reader: false
|
|
70
93
|
cattr_accessor :sql_executer, instance_writer: false, instance_reader: false
|
|
71
94
|
cattr_accessor :alter_extra, instance_writer: false, instance_reader: false
|
|
95
|
+
cattr_accessor :options, instance_writer: false, instance_reader: false
|
|
72
96
|
|
|
73
97
|
class << self
|
|
74
98
|
def without_operation(callback = nil)
|
|
@@ -96,9 +120,11 @@ module Ridgepole
|
|
|
96
120
|
self.alter_extra = nil
|
|
97
121
|
end
|
|
98
122
|
|
|
99
|
-
def expand_execute(connection)
|
|
123
|
+
def expand_execute(connection, options)
|
|
100
124
|
return if connection.is_a?(ConnectionAdapterExt)
|
|
101
125
|
|
|
126
|
+
self.options = options
|
|
127
|
+
|
|
102
128
|
connection.class_eval do
|
|
103
129
|
prepend ConnectionAdapterExt
|
|
104
130
|
end
|
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.1.
|
|
4
|
+
version: 3.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Genki Sugawara
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
version: '6.1'
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '8.
|
|
21
|
+
version: '8.3'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -28,7 +28,7 @@ dependencies:
|
|
|
28
28
|
version: '6.1'
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '8.
|
|
31
|
+
version: '8.3'
|
|
32
32
|
- !ruby/object:Gem::Dependency
|
|
33
33
|
name: diffy
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -119,14 +119,14 @@ dependencies:
|
|
|
119
119
|
requirements:
|
|
120
120
|
- - ">="
|
|
121
121
|
- !ruby/object:Gem::Version
|
|
122
|
-
version: 0.
|
|
122
|
+
version: 0.2.0
|
|
123
123
|
type: :development
|
|
124
124
|
prerelease: false
|
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
|
126
126
|
requirements:
|
|
127
127
|
- - ">="
|
|
128
128
|
- !ruby/object:Gem::Version
|
|
129
|
-
version: 0.
|
|
129
|
+
version: 0.2.0
|
|
130
130
|
- !ruby/object:Gem::Dependency
|
|
131
131
|
name: hash_order_helper
|
|
132
132
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -197,6 +197,20 @@ dependencies:
|
|
|
197
197
|
- - ">="
|
|
198
198
|
- !ruby/object:Gem::Version
|
|
199
199
|
version: 3.0.0
|
|
200
|
+
- !ruby/object:Gem::Dependency
|
|
201
|
+
name: rspec_junit_formatter
|
|
202
|
+
requirement: !ruby/object:Gem::Requirement
|
|
203
|
+
requirements:
|
|
204
|
+
- - ">="
|
|
205
|
+
- !ruby/object:Gem::Version
|
|
206
|
+
version: '0'
|
|
207
|
+
type: :development
|
|
208
|
+
prerelease: false
|
|
209
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
210
|
+
requirements:
|
|
211
|
+
- - ">="
|
|
212
|
+
- !ruby/object:Gem::Version
|
|
213
|
+
version: '0'
|
|
200
214
|
- !ruby/object:Gem::Dependency
|
|
201
215
|
name: rspec-match_fuzzy
|
|
202
216
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -231,14 +245,14 @@ dependencies:
|
|
|
231
245
|
requirements:
|
|
232
246
|
- - '='
|
|
233
247
|
- !ruby/object:Gem::Version
|
|
234
|
-
version: 1.
|
|
248
|
+
version: 1.85.1
|
|
235
249
|
type: :development
|
|
236
250
|
prerelease: false
|
|
237
251
|
version_requirements: !ruby/object:Gem::Requirement
|
|
238
252
|
requirements:
|
|
239
253
|
- - '='
|
|
240
254
|
- !ruby/object:Gem::Version
|
|
241
|
-
version: 1.
|
|
255
|
+
version: 1.85.1
|
|
242
256
|
- !ruby/object:Gem::Dependency
|
|
243
257
|
name: rubocop-rake
|
|
244
258
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -281,6 +295,34 @@ dependencies:
|
|
|
281
295
|
- - ">="
|
|
282
296
|
- !ruby/object:Gem::Version
|
|
283
297
|
version: '0'
|
|
298
|
+
- !ruby/object:Gem::Dependency
|
|
299
|
+
name: simplecov-cobertura
|
|
300
|
+
requirement: !ruby/object:Gem::Requirement
|
|
301
|
+
requirements:
|
|
302
|
+
- - ">="
|
|
303
|
+
- !ruby/object:Gem::Version
|
|
304
|
+
version: '0'
|
|
305
|
+
type: :development
|
|
306
|
+
prerelease: false
|
|
307
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
308
|
+
requirements:
|
|
309
|
+
- - ">="
|
|
310
|
+
- !ruby/object:Gem::Version
|
|
311
|
+
version: '0'
|
|
312
|
+
- !ruby/object:Gem::Dependency
|
|
313
|
+
name: simplecov-html
|
|
314
|
+
requirement: !ruby/object:Gem::Requirement
|
|
315
|
+
requirements:
|
|
316
|
+
- - ">="
|
|
317
|
+
- !ruby/object:Gem::Version
|
|
318
|
+
version: '0'
|
|
319
|
+
type: :development
|
|
320
|
+
prerelease: false
|
|
321
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
322
|
+
requirements:
|
|
323
|
+
- - ">="
|
|
324
|
+
- !ruby/object:Gem::Version
|
|
325
|
+
version: '0'
|
|
284
326
|
- !ruby/object:Gem::Dependency
|
|
285
327
|
name: simplecov-lcov
|
|
286
328
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -364,7 +406,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
364
406
|
- !ruby/object:Gem::Version
|
|
365
407
|
version: '0'
|
|
366
408
|
requirements: []
|
|
367
|
-
rubygems_version:
|
|
409
|
+
rubygems_version: 4.0.3
|
|
368
410
|
specification_version: 4
|
|
369
411
|
summary: Ridgepole is a tool to manage DB schema.
|
|
370
412
|
test_files: []
|