ridgepole 1.0.3 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +12 -0
- data/README.md +16 -1
- data/lib/ridgepole/delta.rb +4 -1
- data/lib/ridgepole/diff.rb +12 -2
- data/lib/ridgepole/dsl_parser.rb +3 -1
- data/lib/ridgepole/ext/abstract_mysql_adapter/partitioning.rb +2 -1
- data/lib/ridgepole/ext/postgresql_adapter/partitioning.rb +26 -14
- 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: 7e42446dbd4e240dcb801dbd26b995e91d9afea59c52131d97e44d4242dd5cb7
|
4
|
+
data.tar.gz: a986057d2aefe29e1ac34f9e8e224eaea86efbf3d900ab095e9b55c1281fc34c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 899809c201c1fe7bed640dac621bb3e98edd4c2606f7107ce3faf4420de2e5ca5087f6499be4b1d66d55e58becd55d6746057033a7dc6b4ea58c3112deadf9c6
|
7
|
+
data.tar.gz: edf7a56bad1187f2e749205afb4c35bbf84b79476b6f00641d452714099374ca69c504425db29dc45b470e769b3cb8381aaa510cc8ca7d0b9cf233e39da7c3a6
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
## 1.0
|
4
4
|
|
5
|
+
### 1.0.6 (2022/06/06)
|
6
|
+
|
7
|
+
* Support Hash partition for PostgreSQL [pull#387](https://github.com/ridgepole/ridgepole/pull/387)
|
8
|
+
|
9
|
+
### 1.0.5 (2022/06/05)
|
10
|
+
|
11
|
+
* Support DEFAULT partition for PostgreSQL [pull#386](https://github.com/ridgepole/ridgepole/pull/386)
|
12
|
+
|
13
|
+
### 1.0.4 (2022/03/28)
|
14
|
+
|
15
|
+
* Add warning for generated column [pull#382](https://github.com/ridgepole/ridgepole/pull/382)
|
16
|
+
|
5
17
|
### 1.0.3 (2022/02/12)
|
6
18
|
|
7
19
|
* Support Rails 7.0.2 [pull#380](https://github.com/ridgepole/ridgepole/pull/380)
|
data/README.md
CHANGED
@@ -11,7 +11,9 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
11
11
|
|
12
12
|
**Notice**
|
13
13
|
|
14
|
-
|
14
|
+
* ActiveRecord 7.x has some incompatible changes. If you get unintended differences in `datetime`, add `precision`.
|
15
|
+
* cf. https://github.com/ridgepole/ridgepole/issues/381
|
16
|
+
* For ActiveRecord 7.x series, please use AcriveRecord 7.0.2 or higher / Ridgepole 1.0.3 or higher.
|
15
17
|
* cf. https://github.com/ridgepole/ridgepole/pull/380
|
16
18
|
* ActiveRecord 6.1 is supported in ridgepole v0.9, but the ActiveRecord dump has been changed, so there is a difference between ActiveRecord 5.x/6.0 format.
|
17
19
|
* **If you use ActiveRecord 6.1, please modify Schemafile format**.
|
@@ -212,6 +214,19 @@ activerecord 5.0.0 and activerecord-mysql-awesome dumps a collation rather than
|
|
212
214
|
|
213
215
|
See `mysql> show character set;` to find charset / collation pair for your system.
|
214
216
|
|
217
|
+
## Generated Column (MySQL)
|
218
|
+
|
219
|
+
There should be NO extra white spaces in the expression (such as after comma).
|
220
|
+
Quotes in expression may cause the operations failure with MySQL 8.0.
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
create_table "users", force: :cascade do |t|
|
224
|
+
t.string "last_name"
|
225
|
+
t.string "first_name"
|
226
|
+
t.virtual "full_name", type: :string, as: "concat(`last_name`,' ',`first_name`)", stored: true
|
227
|
+
end
|
228
|
+
```
|
229
|
+
|
215
230
|
## Execute
|
216
231
|
```ruby
|
217
232
|
create_table "authors", force: :cascade do |t|
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -349,7 +349,10 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
349
349
|
|
350
350
|
append_change_foreign_keys(table_name, foreign_keys, pre_buf_for_fk, post_buf_for_fk, @options) unless foreign_keys.empty?
|
351
351
|
|
352
|
-
|
352
|
+
if table_options || table_charset || table_collation
|
353
|
+
append_change_table_raw_options(table_name, table_options, table_charset, table_collation,
|
354
|
+
buf)
|
355
|
+
end
|
353
356
|
|
354
357
|
append_change_table_comment(table_name, table_comment, buf) if table_comment
|
355
358
|
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -506,6 +506,14 @@ module Ridgepole
|
|
506
506
|
attrs2.fetch(:options).delete(:comment)
|
507
507
|
end
|
508
508
|
|
509
|
+
if attrs1[:options][:as] != attrs2[:options][:as] && attrs1[:options].fetch(:as, '').delete(' ') == attrs2[:options].fetch(:as, '').delete(' ')
|
510
|
+
@logger.warn(<<-MSG)
|
511
|
+
[WARNING] Same expressions but only differed by white spaces were detected. This operation may fail.
|
512
|
+
Before: '#{attrs1[:options][:as]}'
|
513
|
+
After : '#{attrs2[:options][:as]}'
|
514
|
+
MSG
|
515
|
+
end
|
516
|
+
|
509
517
|
attrs1 == attrs2
|
510
518
|
end
|
511
519
|
|
@@ -632,7 +640,9 @@ MSG
|
|
632
640
|
return
|
633
641
|
end
|
634
642
|
|
635
|
-
|
643
|
+
if from[:partition_definitions].present? && (to[:partition_definitions] & from[:partition_definitions]).empty?
|
644
|
+
raise "All partition is different. please check partition settings.to: #{to}, from: #{from}"
|
645
|
+
end
|
636
646
|
|
637
647
|
scan_partition_definition_chanage(from, to, table_delta)
|
638
648
|
end
|
@@ -649,7 +659,7 @@ MSG
|
|
649
659
|
|
650
660
|
(from_partitions.keys - to_partitions.keys).each do |name|
|
651
661
|
partition_definitions_delta[:delete] ||= {}
|
652
|
-
partition_definitions_delta[:delete][name] = attrs.merge(
|
662
|
+
partition_definitions_delta[:delete][name] = attrs.merge(values: from_partitions[name][:values])
|
653
663
|
end
|
654
664
|
|
655
665
|
(to_partitions.keys - from_partitions.keys).each do |name|
|
data/lib/ridgepole/dsl_parser.rb
CHANGED
@@ -40,7 +40,9 @@ module Ridgepole
|
|
40
40
|
# NOTE: For composite primary keys, the first column of the primary key is used as the foreign key index
|
41
41
|
next if Array(attrs[:options][:primary_key]).first == fk_index
|
42
42
|
|
43
|
-
raise
|
43
|
+
raise("The column `#{fk_index}` of the table `#{table_name}` has a foreign key but no index." \
|
44
|
+
' Although InnoDB creates an index automatically,' \
|
45
|
+
' please add one explicitly in order for ridgepole to manage it.')
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -46,7 +46,8 @@ module Ridgepole
|
|
46
46
|
|
47
47
|
# SchemaStatements
|
48
48
|
def create_partition(table_name, type:, columns:, partition_definitions:)
|
49
|
-
execute schema_creation.accept(ActiveRecord::ConnectionAdapters::PartitionOptions.new(table_name, type, columns,
|
49
|
+
execute schema_creation.accept(ActiveRecord::ConnectionAdapters::PartitionOptions.new(table_name, type, columns,
|
50
|
+
partition_definitions: partition_definitions))
|
50
51
|
end
|
51
52
|
|
52
53
|
def add_partition(table_name, name:, values:)
|
@@ -51,23 +51,31 @@ module Ridgepole
|
|
51
51
|
ORDER BY p.relname
|
52
52
|
SQL
|
53
53
|
|
54
|
-
partition_definitions = partition_info.map do |
|
55
|
-
values =
|
56
|
-
|
57
|
-
values = row[1].match(/FOR VALUES IN \((?<csv>.+)\)$/)[:csv].split(',').map(&:strip).map { |value| cast_value(value) }
|
58
|
-
{ in: Array.wrap(values) }
|
59
|
-
when :range
|
60
|
-
match = row[1].match(/FOR VALUES FROM \((?<from>.+)\) TO \((?<to>.+)\)/)
|
61
|
-
from = match[:from].split(',').map(&:strip).map { |value| cast_value(value) }
|
62
|
-
to = match[:to].split(',').map(&:strip).map { |value| cast_value(value) }
|
63
|
-
{ from: from, to: to }
|
54
|
+
partition_definitions = partition_info.map do |name, val_str|
|
55
|
+
values = if val_str == 'DEFAULT'
|
56
|
+
{ default: true }
|
64
57
|
else
|
65
|
-
|
58
|
+
case options[:type]
|
59
|
+
when :list
|
60
|
+
values = val_str.match(/FOR VALUES IN \((?<csv>.+)\)$/)[:csv].split(',').map(&:strip).map { |value| cast_value(value) }
|
61
|
+
{ in: Array.wrap(values) }
|
62
|
+
when :range
|
63
|
+
match = val_str.match(/FOR VALUES FROM \((?<from>.+)\) TO \((?<to>.+)\)/)
|
64
|
+
from = match[:from].split(',').map(&:strip).map { |value| cast_value(value) }
|
65
|
+
to = match[:to].split(',').map(&:strip).map { |value| cast_value(value) }
|
66
|
+
{ from: from, to: to }
|
67
|
+
when :hash
|
68
|
+
match = val_str.match(/FOR VALUES WITH \(modulus (?<modulus>\d+), remainder (?<remainder>\d+)\)/)
|
69
|
+
{ modulus: match[:modulus].to_i, remainder: match[:remainder].to_i }
|
70
|
+
else
|
71
|
+
raise NotImplementedError
|
72
|
+
end
|
66
73
|
end
|
67
|
-
{ name:
|
74
|
+
{ name: name, values: values }
|
68
75
|
end
|
69
76
|
|
70
|
-
ActiveRecord::ConnectionAdapters::PartitionOptions.new(table_name, options[:type], options[:columns],
|
77
|
+
ActiveRecord::ConnectionAdapters::PartitionOptions.new(table_name, options[:type], options[:columns],
|
78
|
+
partition_definitions: partition_definitions)
|
71
79
|
end
|
72
80
|
|
73
81
|
def cast_value(value)
|
@@ -97,12 +105,16 @@ module Ridgepole
|
|
97
105
|
|
98
106
|
# SchemaStatements
|
99
107
|
def add_partition(table_name, name:, values:)
|
100
|
-
condition = if values.key?(:
|
108
|
+
condition = if values.key?(:default)
|
109
|
+
'DEFAULT'
|
110
|
+
elsif values.key?(:in)
|
101
111
|
"FOR VALUES IN (#{values[:in].map { |v| quote_value(v) }.join(',')})"
|
102
112
|
elsif values.key?(:to)
|
103
113
|
from = values[:from].map { |v| quote_value(v) }.join(',')
|
104
114
|
to = values[:to].map { |v| quote_value(v) }.join(',')
|
105
115
|
"FOR VALUES FROM (#{from}) TO (#{to})"
|
116
|
+
elsif values.key?(:modulus)
|
117
|
+
"FOR VALUES WITH (modulus #{values[:modulus]}, remainder #{values[:remainder]})"
|
106
118
|
else
|
107
119
|
raise NotImplementedError
|
108
120
|
end
|
data/lib/ridgepole/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridgepole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -342,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
342
342
|
- !ruby/object:Gem::Version
|
343
343
|
version: '0'
|
344
344
|
requirements: []
|
345
|
-
rubygems_version: 3.
|
345
|
+
rubygems_version: 3.3.7
|
346
346
|
signing_key:
|
347
347
|
specification_version: 4
|
348
348
|
summary: Ridgepole is a tool to manage DB schema.
|