ridgepole 3.0.4 → 3.1.1
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 +15 -0
- data/bin/ridgepole +2 -0
- data/lib/ridgepole/client.rb +1 -0
- data/lib/ridgepole/default_limit.rb +3 -2
- data/lib/ridgepole/delta.rb +9 -3
- data/lib/ridgepole/diff.rb +8 -0
- data/lib/ridgepole/ext/schema_dumper/disable_sort_columns.rb +28 -0
- data/lib/ridgepole/ext/schema_dumper/foreign_keys.rb +68 -0
- data/lib/ridgepole/version.rb +1 -1
- data/lib/ridgepole.rb +1 -1
- metadata +10 -9
- data/lib/ridgepole/ext/schema_dumper.rb +0 -66
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz: '
|
|
3
|
+
metadata.gz: 90db85660b9c1b91946bec50b7af82e03d3b686a3270ba4c12f7253dd31ecd40
|
|
4
|
+
data.tar.gz: '09660a78f0e35155b58423d737391b531405aa895edab86bcc8f6f4213461fef'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e86c295eaafec04bcd2235932312e74d327abb7db2f5be519da092c87a585ade3c9ce7887720426b76ad532ec7e467e4cebd1f570e9a8cb6b0ff3dbcba7f13e
|
|
7
|
+
data.tar.gz: 55dc8d759ec3d788fc07f24ca15c48ca323166bf838f6ebe8ae13383192c5c15577da07d2f431f30c5c8571dfed24fa90dd62aa72cd20afff7abc40af0bca4ba
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## 3.0
|
|
4
4
|
|
|
5
|
+
### 3.1.1 (2025/10/31)
|
|
6
|
+
|
|
7
|
+
- Add `--disable-sort-columns` option [pull#601](https://github.com/ridgepole/ridgepole/pull/601)
|
|
8
|
+
|
|
9
|
+
### 3.1.0 (2025/10/30)
|
|
10
|
+
|
|
11
|
+
- Support Rails 8.1 [pull#589](https://github.com/ridgepole/ridgepole/pull/589)
|
|
12
|
+
- Support for migrating PostgreSQL table comments [pull#587](https://github.com/ridgepole/ridgepole/pull/587)
|
|
13
|
+
|
|
5
14
|
### 3.0.4 (2025/08/31)
|
|
6
15
|
|
|
7
16
|
- Fix checking foreign key without index [pull#571](https://github.com/ridgepole/ridgepole/pull/571)
|
data/README.md
CHANGED
|
@@ -9,7 +9,14 @@ 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://coveralls.io/github/ridgepole/ridgepole?branch=3.0)
|
|
11
11
|
|
|
12
|
+
> [!warning]
|
|
13
|
+
> The order of columns when exporting has changed in Rails 8.1. https://github.com/rails/rails/pull/53281
|
|
14
|
+
>
|
|
15
|
+
> If you do not want to sort the columns, use `--disable-sort-columns` option.
|
|
16
|
+
|
|
12
17
|
> [!note]
|
|
18
|
+
> * ridgepole v3.1.0
|
|
19
|
+
> * Support Rails 8.1 (cf. https://github.com/ridgepole/ridgepole/pull/589)
|
|
13
20
|
> * ridgepole v3.0.0
|
|
14
21
|
> * Support Rails 8.0 (cf. https://github.com/ridgepole/ridgepole/pull/504)
|
|
15
22
|
> * ridgepole v2.0.0
|
|
@@ -92,6 +99,7 @@ Usage: ridgepole [options]
|
|
|
92
99
|
--skip-column-comment-change
|
|
93
100
|
--allow-pk-change
|
|
94
101
|
--create-table-with-index
|
|
102
|
+
--disable-sort-columns
|
|
95
103
|
--mysql-dump-auto-increment
|
|
96
104
|
-r, --require LIBS
|
|
97
105
|
--log-file LOG_FILE
|
|
@@ -181,6 +189,13 @@ create_table "user_comments", force: :cascade, renamed_from: "comments" do |t|
|
|
|
181
189
|
end
|
|
182
190
|
```
|
|
183
191
|
|
|
192
|
+
> [!note]
|
|
193
|
+
> When using `renamed_from` on a table, Ridgepole will only perform the rename operation. All other changes to that table (columns, indexes, foreign keys, etc.) will not be detected during the same migration.
|
|
194
|
+
>
|
|
195
|
+
> If you need to rename AND modify a table, do it in two separate steps:
|
|
196
|
+
> 1. First migration: Add `renamed_from` to rename the table
|
|
197
|
+
> 2. Second migration: Remove `renamed_from` and apply your desired changes
|
|
198
|
+
|
|
184
199
|
## Foreign Key
|
|
185
200
|
```ruby
|
|
186
201
|
create_table "parent", force: :cascade do |t|
|
data/bin/ridgepole
CHANGED
|
@@ -139,11 +139,13 @@ ARGV.options do |opt|
|
|
|
139
139
|
opt.on('', '--drop-table-only') { options[:drop_table_only] = true }
|
|
140
140
|
opt.on('', '--mysql-change-table-options') { options[:mysql_change_table_options] = true }
|
|
141
141
|
opt.on('', '--mysql-change-table-comment') { options[:mysql_change_table_comment] = true }
|
|
142
|
+
opt.on('', '--pg-change-table-comment') { options[:postgresql_change_table_comment] = true }
|
|
142
143
|
opt.on('', '--check-relation-type DEF_PK') { |v| options[:check_relation_type] = v }
|
|
143
144
|
opt.on('', '--ignore-table-comment') { options[:ignore_table_comment] = true }
|
|
144
145
|
opt.on('', '--skip-column-comment-change') { options[:skip_column_comment_change] = true }
|
|
145
146
|
opt.on('', '--allow-pk-change') { options[:allow_pk_change] = true }
|
|
146
147
|
opt.on('', '--create-table-with-index') { options[:create_table_with_index] = true }
|
|
148
|
+
opt.on('', '--disable-sort-columns') { options[:disable_sort_columns] = true }
|
|
147
149
|
|
|
148
150
|
opt.on('', '--mysql-dump-auto-increment') do
|
|
149
151
|
options[:mysql_dump_auto_increment] = true
|
data/lib/ridgepole/client.rb
CHANGED
|
@@ -16,6 +16,7 @@ module Ridgepole
|
|
|
16
16
|
@diff = Ridgepole::Diff.new(@options)
|
|
17
17
|
|
|
18
18
|
require 'ridgepole/ext/abstract_mysql_adapter/dump_auto_increment' if @options[:mysql_dump_auto_increment]
|
|
19
|
+
require 'ridgepole/ext/schema_dumper/disable_sort_columns' if @options[:disable_sort_columns]
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def dump(&block)
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
module Ridgepole
|
|
4
4
|
class DefaultsLimit
|
|
5
5
|
DEFAULT_LIMIT_FOR_MYSQL = {
|
|
6
|
-
boolean: 1,
|
|
7
6
|
integer: 4,
|
|
8
7
|
bigint: 8,
|
|
9
8
|
float: 24,
|
|
10
9
|
string: 255,
|
|
11
10
|
text: 65_535,
|
|
12
11
|
binary: 65_535,
|
|
13
|
-
}.
|
|
12
|
+
}.tap do |limits|
|
|
13
|
+
limits[:boolean] = 1 if ActiveRecord.gem_version < Gem::Version.new('8.1.0.beta1')
|
|
14
|
+
end.freeze
|
|
14
15
|
|
|
15
16
|
DEFAULTS_LIMITS = {
|
|
16
17
|
mysql2: DEFAULT_LIMIT_FOR_MYSQL,
|
data/lib/ridgepole/delta.rb
CHANGED
|
@@ -328,8 +328,14 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
|
328
328
|
end
|
|
329
329
|
|
|
330
330
|
def append_change_table_comment(table_name, table_comment, buf)
|
|
331
|
-
|
|
332
|
-
|
|
331
|
+
if Ridgepole::ConnectionAdapters.postgresql?
|
|
332
|
+
buf.puts(<<-RUBY)
|
|
333
|
+
change_table_comment(#{table_name.inspect}, #{table_comment.inspect})
|
|
334
|
+
RUBY
|
|
335
|
+
else
|
|
336
|
+
comment_literal = "COMMENT=#{ActiveRecord::Base.connection.quote(table_comment)}"
|
|
337
|
+
append_change_table_options(table_name, comment_literal, buf)
|
|
338
|
+
end
|
|
333
339
|
end
|
|
334
340
|
|
|
335
341
|
def append_change(table_name, attrs, buf, pre_buf_for_fk, post_buf_for_fk)
|
|
@@ -438,7 +444,7 @@ rename_column(#{table_name.inspect}, #{from_column_name.inspect}, #{to_column_na
|
|
|
438
444
|
options = attrs[:options] || {}
|
|
439
445
|
|
|
440
446
|
# Fix for https://github.com/rails/rails/commit/7f0567b43b73b1bd1a16bfac9cd32fcbf1321b51
|
|
441
|
-
if Ridgepole::ConnectionAdapters.mysql?
|
|
447
|
+
if Ridgepole::ConnectionAdapters.mysql?
|
|
442
448
|
options[:comment] = nil unless options.key?(:comment)
|
|
443
449
|
end
|
|
444
450
|
|
data/lib/ridgepole/diff.rb
CHANGED
|
@@ -157,6 +157,14 @@ module Ridgepole
|
|
|
157
157
|
end
|
|
158
158
|
end
|
|
159
159
|
|
|
160
|
+
if Ridgepole::ConnectionAdapters.postgresql?
|
|
161
|
+
if @options[:postgresql_change_table_comment] && (from[:comment] != to[:comment])
|
|
162
|
+
from.delete(:comment)
|
|
163
|
+
to_comment = to.delete(:comment)
|
|
164
|
+
table_delta[:table_comment] = to_comment
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
160
168
|
if @options[:dump_without_table_options]
|
|
161
169
|
from.delete(:options)
|
|
162
170
|
from.delete(:charset)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_record/schema_dumper'
|
|
4
|
+
|
|
5
|
+
module Ridgepole
|
|
6
|
+
module Ext
|
|
7
|
+
module SchemaDumper
|
|
8
|
+
module DisableSortColumns
|
|
9
|
+
def table(table, stream)
|
|
10
|
+
def @connection.columns(*_args)
|
|
11
|
+
cols = super
|
|
12
|
+
def cols.sort_by(*_args, &_block)
|
|
13
|
+
self
|
|
14
|
+
end
|
|
15
|
+
cols
|
|
16
|
+
end
|
|
17
|
+
super
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module ActiveRecord
|
|
25
|
+
class SchemaDumper
|
|
26
|
+
prepend Ridgepole::Ext::SchemaDumper::DisableSortColumns
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_record/schema_dumper'
|
|
4
|
+
|
|
5
|
+
module Ridgepole
|
|
6
|
+
module Ext
|
|
7
|
+
module SchemaDumper
|
|
8
|
+
module ForeignKeys
|
|
9
|
+
def self.prepended(klass)
|
|
10
|
+
klass.extend ClassMethods
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ClassMethods
|
|
14
|
+
attr_reader :__with_default_fk_name
|
|
15
|
+
|
|
16
|
+
def with_default_fk_name(value)
|
|
17
|
+
@__with_default_fk_name = value
|
|
18
|
+
yield
|
|
19
|
+
ensure
|
|
20
|
+
remove_instance_variable(:@__with_default_fk_name)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def foreign_keys(table, stream)
|
|
25
|
+
return super unless ActiveRecord::SchemaDumper.__with_default_fk_name
|
|
26
|
+
|
|
27
|
+
if (foreign_keys = @connection.foreign_keys(table)).any?
|
|
28
|
+
add_foreign_key_statements = foreign_keys.map do |foreign_key|
|
|
29
|
+
parts = [
|
|
30
|
+
"add_foreign_key #{remove_prefix_and_suffix(foreign_key.from_table).inspect}",
|
|
31
|
+
remove_prefix_and_suffix(foreign_key.to_table).inspect
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
parts << "column: #{foreign_key.column.inspect}" if foreign_key.column != foreign_key_column_for(foreign_key)
|
|
35
|
+
|
|
36
|
+
parts << "primary_key: #{foreign_key.primary_key.inspect}" if foreign_key.custom_primary_key?
|
|
37
|
+
|
|
38
|
+
parts << "name: #{foreign_key.name.inspect}"
|
|
39
|
+
|
|
40
|
+
parts << "on_update: #{foreign_key.on_update.inspect}" if foreign_key.on_update
|
|
41
|
+
parts << "on_delete: #{foreign_key.on_delete.inspect}" if foreign_key.on_delete
|
|
42
|
+
|
|
43
|
+
" #{parts.join(', ')}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
stream.puts add_foreign_key_statements.sort.join("\n")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def foreign_key_column_for(foreign_key)
|
|
53
|
+
if ActiveRecord.gem_version < Gem::Version.new('7.1.0')
|
|
54
|
+
@connection.foreign_key_column_for(foreign_key.to_table)
|
|
55
|
+
else
|
|
56
|
+
@connection.foreign_key_column_for(foreign_key.to_table, 'id')
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
module ActiveRecord
|
|
65
|
+
class SchemaDumper
|
|
66
|
+
prepend Ridgepole::Ext::SchemaDumper::ForeignKeys
|
|
67
|
+
end
|
|
68
|
+
end
|
data/lib/ridgepole/version.rb
CHANGED
data/lib/ridgepole.rb
CHANGED
|
@@ -17,7 +17,7 @@ module Ridgepole; end
|
|
|
17
17
|
|
|
18
18
|
require 'ridgepole/ext/abstract_adapter/disable_table_options'
|
|
19
19
|
require 'ridgepole/ext/pp_sort_hash'
|
|
20
|
-
require 'ridgepole/ext/schema_dumper'
|
|
20
|
+
require 'ridgepole/ext/schema_dumper/foreign_keys'
|
|
21
21
|
require 'ridgepole/client'
|
|
22
22
|
require 'ridgepole/connection_adapters'
|
|
23
23
|
require 'ridgepole/default_limit'
|
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.
|
|
4
|
+
version: 3.1.1
|
|
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.2'
|
|
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.2'
|
|
32
32
|
- !ruby/object:Gem::Dependency
|
|
33
33
|
name: diffy
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -217,28 +217,28 @@ dependencies:
|
|
|
217
217
|
requirements:
|
|
218
218
|
- - ">="
|
|
219
219
|
- !ruby/object:Gem::Version
|
|
220
|
-
version: 0.
|
|
220
|
+
version: 0.2.0
|
|
221
221
|
type: :development
|
|
222
222
|
prerelease: false
|
|
223
223
|
version_requirements: !ruby/object:Gem::Requirement
|
|
224
224
|
requirements:
|
|
225
225
|
- - ">="
|
|
226
226
|
- !ruby/object:Gem::Version
|
|
227
|
-
version: 0.
|
|
227
|
+
version: 0.2.0
|
|
228
228
|
- !ruby/object:Gem::Dependency
|
|
229
229
|
name: rubocop
|
|
230
230
|
requirement: !ruby/object:Gem::Requirement
|
|
231
231
|
requirements:
|
|
232
232
|
- - '='
|
|
233
233
|
- !ruby/object:Gem::Version
|
|
234
|
-
version: 1.
|
|
234
|
+
version: 1.81.6
|
|
235
235
|
type: :development
|
|
236
236
|
prerelease: false
|
|
237
237
|
version_requirements: !ruby/object:Gem::Requirement
|
|
238
238
|
requirements:
|
|
239
239
|
- - '='
|
|
240
240
|
- !ruby/object:Gem::Version
|
|
241
|
-
version: 1.
|
|
241
|
+
version: 1.81.6
|
|
242
242
|
- !ruby/object:Gem::Dependency
|
|
243
243
|
name: rubocop-rake
|
|
244
244
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -337,7 +337,8 @@ files:
|
|
|
337
337
|
- lib/ridgepole/ext/abstract_adapter/disable_table_options.rb
|
|
338
338
|
- lib/ridgepole/ext/abstract_mysql_adapter/dump_auto_increment.rb
|
|
339
339
|
- lib/ridgepole/ext/pp_sort_hash.rb
|
|
340
|
-
- lib/ridgepole/ext/schema_dumper.rb
|
|
340
|
+
- lib/ridgepole/ext/schema_dumper/disable_sort_columns.rb
|
|
341
|
+
- lib/ridgepole/ext/schema_dumper/foreign_keys.rb
|
|
341
342
|
- lib/ridgepole/external_sql_executer.rb
|
|
342
343
|
- lib/ridgepole/logger.rb
|
|
343
344
|
- lib/ridgepole/migration_ext.rb
|
|
@@ -363,7 +364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
363
364
|
- !ruby/object:Gem::Version
|
|
364
365
|
version: '0'
|
|
365
366
|
requirements: []
|
|
366
|
-
rubygems_version: 3.
|
|
367
|
+
rubygems_version: 3.7.2
|
|
367
368
|
specification_version: 4
|
|
368
369
|
summary: Ridgepole is a tool to manage DB schema.
|
|
369
370
|
test_files: []
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'active_record/schema_dumper'
|
|
4
|
-
|
|
5
|
-
module Ridgepole
|
|
6
|
-
module Ext
|
|
7
|
-
module SchemaDumper
|
|
8
|
-
def self.prepended(klass)
|
|
9
|
-
klass.extend ClassMethods
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
module ClassMethods
|
|
13
|
-
attr_reader :__with_default_fk_name
|
|
14
|
-
|
|
15
|
-
def with_default_fk_name(value)
|
|
16
|
-
@__with_default_fk_name = value
|
|
17
|
-
yield
|
|
18
|
-
ensure
|
|
19
|
-
remove_instance_variable(:@__with_default_fk_name)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def foreign_keys(table, stream)
|
|
24
|
-
return super unless ActiveRecord::SchemaDumper.__with_default_fk_name
|
|
25
|
-
|
|
26
|
-
if (foreign_keys = @connection.foreign_keys(table)).any?
|
|
27
|
-
add_foreign_key_statements = foreign_keys.map do |foreign_key|
|
|
28
|
-
parts = [
|
|
29
|
-
"add_foreign_key #{remove_prefix_and_suffix(foreign_key.from_table).inspect}",
|
|
30
|
-
remove_prefix_and_suffix(foreign_key.to_table).inspect
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
parts << "column: #{foreign_key.column.inspect}" if foreign_key.column != foreign_key_column_for(foreign_key)
|
|
34
|
-
|
|
35
|
-
parts << "primary_key: #{foreign_key.primary_key.inspect}" if foreign_key.custom_primary_key?
|
|
36
|
-
|
|
37
|
-
parts << "name: #{foreign_key.name.inspect}"
|
|
38
|
-
|
|
39
|
-
parts << "on_update: #{foreign_key.on_update.inspect}" if foreign_key.on_update
|
|
40
|
-
parts << "on_delete: #{foreign_key.on_delete.inspect}" if foreign_key.on_delete
|
|
41
|
-
|
|
42
|
-
" #{parts.join(', ')}"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
stream.puts add_foreign_key_statements.sort.join("\n")
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
def foreign_key_column_for(foreign_key)
|
|
52
|
-
if ActiveRecord.gem_version < Gem::Version.new('7.1.0')
|
|
53
|
-
@connection.foreign_key_column_for(foreign_key.to_table)
|
|
54
|
-
else
|
|
55
|
-
@connection.foreign_key_column_for(foreign_key.to_table, 'id')
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
module ActiveRecord
|
|
63
|
-
class SchemaDumper
|
|
64
|
-
prepend Ridgepole::Ext::SchemaDumper
|
|
65
|
-
end
|
|
66
|
-
end
|