ridgepole 1.1.0 → 1.2.0
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/Appraisals +3 -12
- data/CHANGELOG.md +9 -1
- data/README.md +3 -2
- data/docker-compose.yml +3 -3
- data/gemfiles/activerecord_6.0.gemfile +1 -1
- data/gemfiles/activerecord_6.1.gemfile +1 -1
- data/gemfiles/activerecord_7.0.gemfile +1 -1
- data/lib/ridgepole/delta.rb +42 -0
- data/lib/ridgepole/diff.rb +33 -0
- data/lib/ridgepole/dsl_parser/context.rb +15 -0
- data/lib/ridgepole/dsl_parser/table_definition.rb +38 -20
- data/lib/ridgepole/version.rb +1 -1
- metadata +2 -4
- data/gemfiles/activerecord_5.1.gemfile +0 -7
- data/gemfiles/activerecord_5.2.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '068fca35b633df2e4bc3b2d8ad5d2553496396a78c16ca371f18efc4dbad6adf'
|
4
|
+
data.tar.gz: c908229a06ddcbbf28e14b28af7f52f63c933d271db2e24231f6ed588fe5a1a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6456e47a675dbdeb21ce56c9ed6091e823031ca082b191b7fb0438880d54ee6aea51988d4d9c5e07ded0e684a683d22f0d613cd3697c7c6d12ef6948b41e972e
|
7
|
+
data.tar.gz: 4b9f3b573975e0be50dec442e7db23688374754306082275bcc711e20e5813f2c4ca1975993797e02fd5b963cf396b7f5bbd2cd869f02aee468c8d07ce98e3c1
|
data/Appraisals
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
appraise 'activerecord-5.1' do
|
4
|
-
gem 'activerecord', '~> 5.1.0'
|
5
|
-
end
|
6
|
-
|
7
|
-
appraise 'activerecord-5.2' do
|
8
|
-
gem 'activerecord', '~> 5.2.0'
|
9
|
-
gem 'mysql2', '~> 0.4.4'
|
10
|
-
end
|
11
|
-
|
12
3
|
appraise 'activerecord-6.0' do
|
13
|
-
gem 'activerecord', '~> 6.0.
|
4
|
+
gem 'activerecord', '~> 6.0.6'
|
14
5
|
end
|
15
6
|
|
16
7
|
appraise 'activerecord-6.1' do
|
17
|
-
gem 'activerecord', '~> 6.1.
|
8
|
+
gem 'activerecord', '~> 6.1.7'
|
18
9
|
end
|
19
10
|
|
20
11
|
appraise 'activerecord-7.0' do
|
21
|
-
gem 'activerecord', '~> 7.0.
|
12
|
+
gem 'activerecord', '~> 7.0.4'
|
22
13
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.2
|
4
|
+
|
5
|
+
### 1.2.0 (2022/09/24)
|
6
|
+
|
7
|
+
* Updated supported column types [pull#399](https://github.com/ridgepole/ridgepole/pull/399) [pull#400](https://github.com/ridgepole/ridgepole/pull/400)
|
8
|
+
* Support check constraint [pull#393](https://github.com/ridgepole/ridgepole/pull/393) [pull#397](https://github.com/ridgepole/ridgepole/pull/397)
|
9
|
+
* Drop suport Rails 5.x [pull#395](https://github.com/ridgepole/ridgepole/pull/395 )
|
10
|
+
|
11
|
+
## 1.1
|
4
12
|
|
5
13
|
### 1.1.0 (2022/06/18)
|
6
14
|
|
data/README.md
CHANGED
@@ -6,11 +6,12 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
6
6
|
(like Chef/Puppet)
|
7
7
|
|
8
8
|
[](http://badge.fury.io/rb/ridgepole)
|
9
|
-
[](https://github.com/ridgepole/ridgepole/actions)
|
10
|
+
[](https://coveralls.io/github/ridgepole/ridgepole?branch=1.2)
|
11
11
|
|
12
12
|
**Notice**
|
13
13
|
|
14
|
+
* Drop support ActiveRecord 5.x in ridgepole v1.2.0.
|
14
15
|
* Partitioning is no longer supported in ridgepole v1.1.0.
|
15
16
|
* ActiveRecord 7.x has some incompatible changes. If you get unintended differences in `datetime`, add `precision`.
|
16
17
|
* cf. https://github.com/ridgepole/ridgepole/issues/381
|
data/docker-compose.yml
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
version: "3.8"
|
2
2
|
services:
|
3
3
|
mysql:
|
4
|
-
image: "mysql:5.6"
|
4
|
+
image: "mysql:5.6.51"
|
5
5
|
ports:
|
6
6
|
- "13316:3306"
|
7
7
|
environment:
|
8
8
|
MYSQL_ROOT_PASSWORD: password
|
9
9
|
mysql57:
|
10
|
-
image: "mysql:5.7"
|
10
|
+
image: "mysql:5.7.39"
|
11
11
|
ports:
|
12
12
|
- "13317:3306"
|
13
13
|
environment:
|
14
14
|
MYSQL_ROOT_PASSWORD: password
|
15
15
|
mysql80:
|
16
|
-
image: "mysql:8.0"
|
16
|
+
image: "mysql:8.0.30"
|
17
17
|
ports:
|
18
18
|
- "13318:3306"
|
19
19
|
environment:
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -245,6 +245,12 @@ create_table(#{table_name.inspect}, #{inspect_options_include_default_proc(optio
|
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
248
|
+
unless (check_constraints = attrs[:check_constraints] || {}).empty?
|
249
|
+
check_constraints.each do |_, check_constraint_attrs|
|
250
|
+
append_add_check_constraint(table_name, check_constraint_attrs, buf, true)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
248
254
|
buf.puts(<<-RUBY)
|
249
255
|
end
|
250
256
|
RUBY
|
@@ -315,6 +321,7 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
315
321
|
primary_key_definition = attrs[:primary_key_definition] || {}
|
316
322
|
indices = attrs[:indices] || {}
|
317
323
|
foreign_keys = attrs[:foreign_keys] || {}
|
324
|
+
check_constraints = attrs[:check_constraints] || {}
|
318
325
|
table_options = attrs[:table_options]
|
319
326
|
table_charset = attrs[:table_charset]
|
320
327
|
table_collation = attrs[:table_collation]
|
@@ -330,6 +337,7 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
330
337
|
end
|
331
338
|
|
332
339
|
append_change_foreign_keys(table_name, foreign_keys, pre_buf_for_fk, post_buf_for_fk, @options) unless foreign_keys.empty?
|
340
|
+
append_change_check_constraints(table_name, check_constraints, buf) unless check_constraints.empty?
|
333
341
|
|
334
342
|
if table_options || table_charset || table_collation
|
335
343
|
append_change_table_raw_options(table_name, table_options, table_charset, table_collation,
|
@@ -511,6 +519,40 @@ remove_foreign_key(#{table_name.inspect}, #{target})
|
|
511
519
|
RUBY
|
512
520
|
end
|
513
521
|
|
522
|
+
def append_change_check_constraints(table_name, delta, buf)
|
523
|
+
(delta[:delete] || {}).each do |_, attrs|
|
524
|
+
append_remove_check_constraint(table_name, attrs, buf)
|
525
|
+
end
|
526
|
+
|
527
|
+
(delta[:add] || {}).each do |_, attrs|
|
528
|
+
append_add_check_constraint(table_name, attrs, buf)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
def append_add_check_constraint(table_name, attrs, buf, force_bulk_change = false)
|
533
|
+
expression = attrs.fetch(:expression)
|
534
|
+
attrs_options = attrs[:options] || {}
|
535
|
+
|
536
|
+
if force_bulk_change
|
537
|
+
buf.puts(<<-RUBY)
|
538
|
+
t.check_constraint(#{expression.inspect}, **#{attrs_options.inspect})
|
539
|
+
RUBY
|
540
|
+
else
|
541
|
+
buf.puts(<<-RUBY)
|
542
|
+
add_check_constraint(#{table_name.inspect}, #{expression.inspect}, **#{attrs_options.inspect})
|
543
|
+
RUBY
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
def append_remove_check_constraint(table_name, attrs, buf)
|
548
|
+
expression = attrs.fetch(:expression)
|
549
|
+
attrs_options = attrs[:options] || {}
|
550
|
+
|
551
|
+
buf.puts(<<-RUBY)
|
552
|
+
remove_check_constraint(#{table_name.inspect}, #{expression.inspect}, **#{attrs_options.inspect})
|
553
|
+
RUBY
|
554
|
+
end
|
555
|
+
|
514
556
|
def delta_execute
|
515
557
|
@delta[:execute] || []
|
516
558
|
end
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -101,6 +101,7 @@ module Ridgepole
|
|
101
101
|
scan_definition_change(from[:definition], to[:definition], from[:indices], table_name, from[:options], table_delta)
|
102
102
|
scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta, from[:options], to[:options])
|
103
103
|
scan_foreign_keys_change(from[:foreign_keys], to[:foreign_keys], table_delta, @options)
|
104
|
+
scan_check_constraints_change(from[:check_constraints], to[:check_constraints], table_delta)
|
104
105
|
|
105
106
|
unless table_delta.empty?
|
106
107
|
delta[:change] ||= {}
|
@@ -472,6 +473,38 @@ module Ridgepole
|
|
472
473
|
table_delta[:foreign_keys] = foreign_keys_delta unless foreign_keys_delta.empty?
|
473
474
|
end
|
474
475
|
|
476
|
+
def scan_check_constraints_change(from, to, table_delta)
|
477
|
+
from = (from || {}).dup
|
478
|
+
to = (to || {}).dup
|
479
|
+
check_constraints_delta = {}
|
480
|
+
|
481
|
+
to.each do |name, to_attrs|
|
482
|
+
from_attrs = from.delete(name)
|
483
|
+
|
484
|
+
if from_attrs
|
485
|
+
if from_attrs != to_attrs
|
486
|
+
check_constraints_delta[:add] ||= {}
|
487
|
+
check_constraints_delta[:add][name] = to_attrs
|
488
|
+
|
489
|
+
check_constraints_delta[:delete] ||= {}
|
490
|
+
check_constraints_delta[:delete][name] = from_attrs
|
491
|
+
end
|
492
|
+
else
|
493
|
+
check_constraints_delta[:add] ||= {}
|
494
|
+
check_constraints_delta[:add][name] = to_attrs
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
unless @options[:merge]
|
499
|
+
from.each do |name, from_attrs|
|
500
|
+
check_constraints_delta[:delete] ||= {}
|
501
|
+
check_constraints_delta[:delete][name] = from_attrs
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
table_delta[:check_constraints] = check_constraints_delta unless check_constraints_delta.empty?
|
506
|
+
end
|
507
|
+
|
475
508
|
# XXX: MySQL only?
|
476
509
|
# https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L760
|
477
510
|
# https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb#L102
|
@@ -91,6 +91,21 @@ module Ridgepole
|
|
91
91
|
}
|
92
92
|
end
|
93
93
|
|
94
|
+
def add_check_constraint(table_name, expression, options = {})
|
95
|
+
table_name = table_name.to_s
|
96
|
+
expression = expression.to_s
|
97
|
+
options[:name] = options[:name].to_s if options[:name]
|
98
|
+
|
99
|
+
idx = options[:name] || expression
|
100
|
+
|
101
|
+
@__definition[table_name] ||= {}
|
102
|
+
@__definition[table_name][:check_constraints] ||= {}
|
103
|
+
@__definition[table_name][:check_constraints][idx] = {
|
104
|
+
expression: expression,
|
105
|
+
options: options,
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
94
109
|
def require(file)
|
95
110
|
schemafile = %r{\A/}.match?(file) ? file : File.join(@__working_dir, file)
|
96
111
|
|
@@ -26,32 +26,41 @@ module Ridgepole
|
|
26
26
|
DEFAULT_PRIMARY_KEY_TYPE = :bigint
|
27
27
|
|
28
28
|
TYPES = {
|
29
|
-
# https://github.com/rails/rails/blob/
|
30
|
-
string: {},
|
31
|
-
text: {},
|
32
|
-
integer: {},
|
29
|
+
# https://github.com/rails/rails/blob/main/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L300-L301
|
33
30
|
bigint: {},
|
34
|
-
float: {},
|
35
|
-
decimal: {},
|
36
|
-
datetime: {},
|
37
|
-
timestamp: {},
|
38
|
-
time: {},
|
39
|
-
date: {},
|
40
31
|
binary: {},
|
41
32
|
boolean: {},
|
33
|
+
date: {},
|
34
|
+
datetime: {},
|
35
|
+
decimal: {},
|
36
|
+
float: {},
|
37
|
+
integer: {},
|
38
|
+
json: {},
|
39
|
+
string: {},
|
40
|
+
text: {},
|
41
|
+
time: {},
|
42
|
+
timestamp: {},
|
43
|
+
virtual: {},
|
42
44
|
|
43
|
-
# https://github.com/rails/rails/blob/
|
45
|
+
# https://github.com/rails/rails/blob/v6.0.6/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L101
|
44
46
|
serial: { null: false },
|
45
47
|
bigserial: { null: false },
|
48
|
+
# string: {},
|
49
|
+
# text: {},
|
50
|
+
# integer: {},
|
51
|
+
# float: {},
|
52
|
+
# decimal: {},
|
53
|
+
# datetime: {},
|
54
|
+
# time: {},
|
55
|
+
# date: {},
|
46
56
|
daterange: {},
|
47
57
|
numrange: {},
|
48
58
|
tsrange: {},
|
49
59
|
tstzrange: {},
|
50
60
|
int4range: {},
|
51
61
|
int8range: {},
|
52
|
-
# binary: {},
|
53
|
-
# boolean: {},
|
54
|
-
# bigint: {}, # dup key
|
62
|
+
# binary: {},
|
63
|
+
# boolean: {},
|
55
64
|
xml: {},
|
56
65
|
tsvector: {},
|
57
66
|
hstore: {},
|
@@ -59,20 +68,25 @@ module Ridgepole
|
|
59
68
|
cidr: {},
|
60
69
|
macaddr: {},
|
61
70
|
uuid: {},
|
62
|
-
json: {},
|
71
|
+
# json: {},
|
63
72
|
jsonb: {},
|
64
73
|
ltree: {},
|
65
74
|
citext: {},
|
66
75
|
point: {},
|
76
|
+
line: {},
|
77
|
+
lseg: {},
|
78
|
+
box: {},
|
79
|
+
path: {},
|
80
|
+
polygon: {},
|
81
|
+
circle: {},
|
67
82
|
bit: {},
|
68
83
|
bit_varying: {},
|
69
84
|
money: {},
|
85
|
+
interval: {},
|
86
|
+
oid: {},
|
70
87
|
|
71
|
-
# https://github.com/
|
72
|
-
|
73
|
-
|
74
|
-
# https://github.com/rails/rails/blob/v5.0.4/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L53
|
75
|
-
# json: {}, # dup key
|
88
|
+
# https://github.com/ridgepole/ridgepole/issues/394
|
89
|
+
timestamptz: {},
|
76
90
|
}.freeze
|
77
91
|
|
78
92
|
TYPES.each do |column_type, default_options|
|
@@ -159,6 +173,10 @@ module Ridgepole
|
|
159
173
|
end
|
160
174
|
end
|
161
175
|
alias belongs_to references
|
176
|
+
|
177
|
+
def check_constraint(expression, options = {})
|
178
|
+
@base.add_check_constraint(@table_name, expression, options)
|
179
|
+
end
|
162
180
|
end
|
163
181
|
end
|
164
182
|
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.
|
4
|
+
version: 1.2.0
|
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-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -288,8 +288,6 @@ files:
|
|
288
288
|
- Rakefile
|
289
289
|
- bin/ridgepole
|
290
290
|
- docker-compose.yml
|
291
|
-
- gemfiles/activerecord_5.1.gemfile
|
292
|
-
- gemfiles/activerecord_5.2.gemfile
|
293
291
|
- gemfiles/activerecord_6.0.gemfile
|
294
292
|
- gemfiles/activerecord_6.1.gemfile
|
295
293
|
- gemfiles/activerecord_7.0.gemfile
|