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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e83bd61a718b5b97d6be9214742e452fce8c54e9bff48e2b604344753138c0bb
4
- data.tar.gz: f2ed01a46f18174e3173f07715002fc222467a341d9e93682910ef2c2497d613
3
+ metadata.gz: 7e42446dbd4e240dcb801dbd26b995e91d9afea59c52131d97e44d4242dd5cb7
4
+ data.tar.gz: a986057d2aefe29e1ac34f9e8e224eaea86efbf3d900ab095e9b55c1281fc34c
5
5
  SHA512:
6
- metadata.gz: 62a7e740ec77f0124b3b9776a3c78fc8186a9f00d0f97917cae79342664f1a77e1f2ce3992e7e6e463c8fad76e2fba92af0f9a6031a70f7d545768dae2942ba1
7
- data.tar.gz: 2f43e6f67be8820450c9fd47ddde4dacabe69778bbc1d3837b9ce8988e6b7393f80df3ed5a400a142a0a20a06c58344aa08490ea81cc25d4fdb10b56de824aec
6
+ metadata.gz: 899809c201c1fe7bed640dac621bb3e98edd4c2606f7107ce3faf4420de2e5ca5087f6499be4b1d66d55e58becd55d6746057033a7dc6b4ea58c3112deadf9c6
7
+ data.tar.gz: edf7a56bad1187f2e749205afb4c35bbf84b79476b6f00641d452714099374ca69c504425db29dc45b470e769b3cb8381aaa510cc8ca7d0b9cf233e39da7c3a6
data/.rubocop.yml CHANGED
@@ -21,7 +21,7 @@ Metrics/ClassLength:
21
21
  Metrics/CyclomaticComplexity:
22
22
  Enabled: false
23
23
  Layout/LineLength:
24
- Enabled: false
24
+ Max: 200
25
25
  Metrics/MethodLength:
26
26
  Enabled: false
27
27
  Metrics/ModuleLength:
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
- For ActiveRecord 7.x series, please use AcriveRecord 7.0.2 or higher / Ridgepole 1.0.3 or higher.
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|
@@ -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
- append_change_table_raw_options(table_name, table_options, table_charset, table_collation, buf) if table_options || table_charset || table_collation
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
 
@@ -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
- raise "All partition is different. please check partition settings.to: #{to}, from: #{from}" if from[:partition_definitions].present? && (to[:partition_definitions] & from[:partition_definitions]).empty?
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(valuve: from_partitions[name][:values])
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|
@@ -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 "The column `#{fk_index}` of the table `#{table_name}` has a foreign key but no index. Although InnoDB creates an index automatically, please add one explicitly in order for ridgepole to manage it."
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, partition_definitions: partition_definitions))
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 |row|
55
- values = case options[:type]
56
- when :list
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
- raise NotImplementedError
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: row[0], values: values }
74
+ { name: name, values: values }
68
75
  end
69
76
 
70
- ActiveRecord::ConnectionAdapters::PartitionOptions.new(table_name, options[:type], options[:columns], partition_definitions: partition_definitions)
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?(:in)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ridgepole
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.6'
5
5
  end
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.3
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-02-11 00:00:00.000000000 Z
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.2.32
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.