ridgepole 0.9.0 → 0.9.5
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/.github/workflows/test.yml +7 -20
- data/.rubocop.yml +5 -4
- data/README.md +13 -3
- data/lib/ridgepole/diff.rb +7 -3
- data/lib/ridgepole/dsl_parser/table_definition.rb +7 -0
- data/lib/ridgepole/execute_expander.rb +1 -1
- data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +1 -0
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +3 -3
- data/spec/mysql/fk/migrate_change_fk_spec.rb +68 -0
- data/spec/mysql/fk/migrate_create_fk_spec.rb +55 -0
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +55 -0
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +45 -0
- data/spec/mysql/migrate/migrate_change_column7_spec.rb +11 -2
- data/spec/mysql/migrate/migrate_create_index_spec.rb +60 -0
- data/spec/spec_const.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4309b6d60e99651b74a3a54dc7600d59a9f4ce195bc3922b1abca232ed02009e
|
4
|
+
data.tar.gz: 73bb8b3ed77c18e4f5d51439aefed10980afe7d9371808787832758d0248c88d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4133de20d4427bc17fd033aeb6bfb5507c730da1c947954b46fece10e0c51c6b855017ef98e6d681f7bb442c26699eef094ca6572871e0be4a34de784fb701d
|
7
|
+
data.tar.gz: 11943e7e1f26c9486542279e270d546c2455bc97b813f22e6dd390cf18217a07a8873301138af70e254b84380db3bba1f3f6b0ba450842ae29c6a881b22ad0c3
|
data/.github/workflows/test.yml
CHANGED
@@ -29,49 +29,36 @@ jobs:
|
|
29
29
|
gemfile: gemfiles/activerecord_6.0.gemfile
|
30
30
|
- ruby: 2.4
|
31
31
|
gemfile: gemfiles/activerecord_6.1.gemfile
|
32
|
-
|
32
|
+
env:
|
33
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
33
34
|
steps:
|
34
35
|
- uses: actions/checkout@v2
|
35
|
-
- uses:
|
36
|
+
- uses: ruby/setup-ruby@v1
|
36
37
|
with:
|
37
38
|
ruby-version: ${{ matrix.ruby }}
|
38
|
-
|
39
|
-
with:
|
40
|
-
path: gemfiles/vendor/bundle
|
41
|
-
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ hashFiles('ridgepole.gemspec', '**/Gemfile', '${{ matrix.gemfile }}') }}
|
42
|
-
restore-keys: |
|
43
|
-
${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.gemfile }}-
|
44
|
-
|
39
|
+
bundler-cache: true
|
45
40
|
- name: Setup dependencies
|
46
41
|
run: |
|
47
42
|
for i in {1..60}; do docker-compose up -d && break; sleep 1; done
|
48
|
-
|
49
|
-
gem install bundler
|
50
|
-
bundle config path vendor/bundle
|
51
|
-
bundle install --jobs 4 --retry 3
|
52
|
-
|
53
43
|
# Wait until database servers start
|
54
|
-
function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 13316 -
|
55
|
-
function mysql57_ping { mysqladmin -u root -h 127.0.0.1 -P 13317 -
|
44
|
+
function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 13316 ping --ssl-mode=DISABLED; }
|
45
|
+
function mysql57_ping { mysqladmin -u root -h 127.0.0.1 -P 13317 ping --ssl-mode=DISABLED; }
|
56
46
|
function pg_ping { PGPASSWORD=password pg_isready -U postgres -h 127.0.0.1 -p 15442; }
|
57
47
|
for i in {1..60}; do mysql_ping && break; sleep 1; done
|
58
48
|
for i in {1..60}; do mysql57_ping && break; sleep 1; done
|
59
49
|
for i in {1..60}; do pg_ping && break; sleep 1; done
|
60
50
|
env:
|
61
|
-
|
62
|
-
|
51
|
+
MYSQL_PWD: password
|
63
52
|
- name: Run tests
|
64
53
|
run: ${{ matrix.env }} bundle exec rake
|
65
54
|
env:
|
66
55
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
67
|
-
|
68
56
|
- name: Coveralls Parallel
|
69
57
|
uses: coverallsapp/github-action@v1.1.2
|
70
58
|
with:
|
71
59
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
72
60
|
flag-name: run-${{ matrix.ruby }}-${{ matrix.env }}-${{ matrix.gemfile }}
|
73
61
|
parallel: true
|
74
|
-
|
75
62
|
finish:
|
76
63
|
needs: build
|
77
64
|
runs-on: ubuntu-latest
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
-
-
|
4
|
-
-
|
3
|
+
- "gemfiles/**/*"
|
4
|
+
- "omnibus-ridgepole/**/*"
|
5
|
+
- "vendor/bundle/**/*"
|
5
6
|
TargetRubyVersion: 2.4
|
6
7
|
NewCops: enable
|
7
8
|
Bundler/OrderedGems:
|
8
9
|
Include:
|
9
|
-
-
|
10
|
+
- "Appraisals"
|
10
11
|
Layout/HeredocIndentation:
|
11
12
|
Enabled: false
|
12
13
|
Metrics/AbcSize:
|
@@ -33,7 +34,7 @@ Style/GuardClause:
|
|
33
34
|
Enabled: false
|
34
35
|
Style/MixinUsage:
|
35
36
|
Exclude:
|
36
|
-
-
|
37
|
+
- "spec/**/*"
|
37
38
|
Style/TrailingCommaInHashLiteral:
|
38
39
|
EnforcedStyleForMultiline: consistent_comma
|
39
40
|
Layout/ClosingHeredocIndentation:
|
data/README.md
CHANGED
@@ -130,11 +130,21 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
130
130
|
* `>= 0.8.13`
|
131
131
|
* Support `serial` and `bigserial` column types ([pull#321](https://github.com/winebarrel/ridgepole/pull/321))
|
132
132
|
* `>= 0.9.0`
|
133
|
-
* Remove `--mysql-alter
|
133
|
+
* Remove `--mysql-use-alter` option ([pull#330](https://github.com/winebarrel/ridgepole/pull/330))
|
134
134
|
* Add `--table-hash-options` option ([pull#331](https://github.com/winebarrel/ridgepole/pull/331))
|
135
135
|
* Support Rails 6.1 ([pull#323](https://github.com/winebarrel/ridgepole/pull/323))
|
136
136
|
* Disable Rails 5.0 support ([pull#335](https://github.com/winebarrel/ridgepole/pull/335))
|
137
137
|
* Fix PK AUTO_INCREMENT change bug ([pull#334](https://github.com/winebarrel/ridgepole/pull/334))
|
138
|
+
* `>= 0.9.1`
|
139
|
+
* Support `t.foreign_key` ([pull#348](https://github.com/winebarrel/ridgepole/pull/348))
|
140
|
+
* `>= 0.9.2`
|
141
|
+
* Support `t.column index option` ([pull#353](https://github.com/winebarrel/ridgepole/pull/353))
|
142
|
+
* `>= 0.9.3`
|
143
|
+
* Fix `limit` option for `t.integer` ([pull#354](https://github.com/winebarrel/ridgepole/pull/354))
|
144
|
+
* `>= 0.9.4`
|
145
|
+
* Fix `--alter-extra` option for unique index ([pull#356](https://github.com/winebarrel/ridgepole/pull/356))
|
146
|
+
* `>= 0.9.5`
|
147
|
+
* Call `super` in `disable_table_options.rb` ([pull#357](https://github.com/winebarrel/ridgepole/pull/357))
|
138
148
|
</details>
|
139
149
|
|
140
150
|
**Notice**
|
@@ -296,8 +306,8 @@ create_table "parent", force: :cascade do |t|
|
|
296
306
|
end
|
297
307
|
|
298
308
|
create_table "child", id: false, force: :cascade do |t|
|
299
|
-
t.
|
300
|
-
t.
|
309
|
+
t.bigint "id"
|
310
|
+
t.bigint "parent_id"
|
301
311
|
end
|
302
312
|
|
303
313
|
add_index "child", ["parent_id"], name: "par_ind", using: :btree
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -399,9 +399,13 @@ module Ridgepole
|
|
399
399
|
if Ridgepole::ConnectionAdapters.mysql?
|
400
400
|
opts[:unsigned] = false unless opts.key?(:unsigned)
|
401
401
|
|
402
|
-
if
|
403
|
-
|
404
|
-
|
402
|
+
if attrs[:type] == :integer && opts[:limit]
|
403
|
+
min = Ridgepole::DefaultsLimit.default_limit(:integer, @options)
|
404
|
+
max = Ridgepole::DefaultsLimit.default_limit(:bigint, @options)
|
405
|
+
if min < opts[:limit] && opts[:limit] <= max
|
406
|
+
attrs[:type] = :bigint
|
407
|
+
opts.delete(:limit)
|
408
|
+
end
|
405
409
|
end
|
406
410
|
|
407
411
|
if opts[:size] && (attrs[:type] == :text || attrs[:type] == :blob || attrs[:type] == :binary)
|
@@ -13,11 +13,14 @@ module Ridgepole
|
|
13
13
|
|
14
14
|
def column(name, type, options = {})
|
15
15
|
name = name.to_s
|
16
|
+
index_options = options.key?(:index) ? options.delete(:index) : false
|
16
17
|
|
17
18
|
@__definition[name] = {
|
18
19
|
type: type,
|
19
20
|
options: options,
|
20
21
|
}
|
22
|
+
|
23
|
+
index(name, index_options.is_a?(Hash) ? index_options : {}) if index_options
|
21
24
|
end
|
22
25
|
|
23
26
|
DEFAULT_PRIMARY_KEY_TYPE = :bigint
|
@@ -120,6 +123,10 @@ module Ridgepole
|
|
120
123
|
@base.add_index(@table_name, name, options)
|
121
124
|
end
|
122
125
|
|
126
|
+
def foreign_key(name, options = {})
|
127
|
+
@base.add_foreign_key(@table_name, name, options)
|
128
|
+
end
|
129
|
+
|
123
130
|
def timestamps(*args)
|
124
131
|
options = { null: false }.merge(args.extract_options!)
|
125
132
|
column(:created_at, :datetime, options)
|
@@ -50,7 +50,7 @@ module Ridgepole
|
|
50
50
|
case sql
|
51
51
|
when /\AALTER\b/i
|
52
52
|
sql += ',' + Ridgepole::ExecuteExpander.alter_extra
|
53
|
-
when /\A(CREATE|DROP)\s+INDEX\b/i
|
53
|
+
when /\A(CREATE|DROP)\s+((ONLINE|OFFLINE)\s+)?((UNIQUE|FULLTEXT|SPATIAL)\s+)?INDEX\b/i
|
54
54
|
# https://dev.mysql.com/doc/refman/5.6/en/create-index.html
|
55
55
|
# https://dev.mysql.com/doc/refman/5.6/en/drop-index.html
|
56
56
|
sql += ' ' + Ridgepole::ExecuteExpander.alter_extra.tr(',', ' ')
|
data/lib/ridgepole/version.rb
CHANGED
data/ridgepole.gemspec
CHANGED
@@ -8,10 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = 'ridgepole'
|
9
9
|
spec.version = Ridgepole::VERSION
|
10
10
|
spec.authors = ['Genki Sugawara']
|
11
|
-
spec.email = ['sugawara@
|
11
|
+
spec.email = ['sugawara@winebarrel.jp']
|
12
12
|
spec.summary = 'Ridgepole is a tool to manage DB schema.'
|
13
13
|
spec.description = 'Ridgepole is a tool to manage DB schema. It defines DB schema using Rails DSL, and updates DB schema according to DSL.'
|
14
|
-
spec.homepage = 'https://github.com/
|
14
|
+
spec.homepage = 'https://github.com/ridgepole/ridgepole'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
36
36
|
spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.3'
|
37
37
|
spec.add_development_dependency 'rspec-match_ruby', '>= 0.1.3'
|
38
|
-
spec.add_development_dependency 'rubocop', '1.
|
38
|
+
spec.add_development_dependency 'rubocop', '1.9.1'
|
39
39
|
spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
|
40
40
|
spec.add_development_dependency 'rubocop-rspec', '>= 2.1.0'
|
41
41
|
spec.add_development_dependency 'simplecov'
|
@@ -57,6 +57,74 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
60
|
+
context 'when change fk using `t.foreign_key`' do
|
61
|
+
let(:actual_dsl) do
|
62
|
+
erbh(<<-ERB)
|
63
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
64
|
+
end
|
65
|
+
|
66
|
+
create_table "child", force: :cascade do |t|
|
67
|
+
t.integer "parent_id"
|
68
|
+
t.index ["parent_id"], name: "par_id"
|
69
|
+
t.foreign_key "parent", name: "child_ibfk_1", on_delete: :cascade
|
70
|
+
end
|
71
|
+
ERB
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:sorted_actual_dsl) do
|
75
|
+
erbh(<<-ERB)
|
76
|
+
create_table "child", force: :cascade do |t|
|
77
|
+
t.integer "parent_id"
|
78
|
+
t.index ["parent_id"], name: "par_id"
|
79
|
+
end
|
80
|
+
|
81
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
82
|
+
end
|
83
|
+
|
84
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
|
85
|
+
ERB
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:expected_dsl) do
|
89
|
+
erbh(<<-ERB)
|
90
|
+
create_table "child", force: :cascade do |t|
|
91
|
+
t.integer "parent_id"
|
92
|
+
t.index ["parent_id"], name: "par_id"
|
93
|
+
end
|
94
|
+
|
95
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
96
|
+
end
|
97
|
+
|
98
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
99
|
+
ERB
|
100
|
+
end
|
101
|
+
|
102
|
+
let(:expected_dsl_using_t_foreign_key) do
|
103
|
+
erbh(<<-ERB)
|
104
|
+
create_table "child", force: :cascade do |t|
|
105
|
+
t.integer "parent_id"
|
106
|
+
t.index ["parent_id"], name: "par_id"
|
107
|
+
t.foreign_key "parent", name: "child_ibfk_1"
|
108
|
+
end
|
109
|
+
|
110
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
111
|
+
end
|
112
|
+
ERB
|
113
|
+
end
|
114
|
+
|
115
|
+
before { subject.diff(actual_dsl).migrate }
|
116
|
+
|
117
|
+
subject { client }
|
118
|
+
|
119
|
+
it {
|
120
|
+
delta = subject.diff(expected_dsl_using_t_foreign_key)
|
121
|
+
expect(delta.differ?).to be_truthy
|
122
|
+
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
123
|
+
delta.migrate
|
124
|
+
expect(subject.dump).to match_ruby expected_dsl
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
60
128
|
context 'when change fk without name' do
|
61
129
|
let(:actual_dsl) do
|
62
130
|
erbh(<<-ERB)
|
@@ -43,6 +43,61 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
43
43
|
}
|
44
44
|
end
|
45
45
|
|
46
|
+
context 'when create fk using `t.foreign_key`' do
|
47
|
+
let(:actual_dsl) do
|
48
|
+
erbh(<<-ERB)
|
49
|
+
create_table "child", force: :cascade do |t|
|
50
|
+
t.integer "parent_id"
|
51
|
+
t.index ["parent_id"], name: "par_id"
|
52
|
+
end
|
53
|
+
|
54
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
55
|
+
end
|
56
|
+
ERB
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:expected_dsl) do
|
60
|
+
erbh(actual_dsl + <<-ERB)
|
61
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
62
|
+
ERB
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:expected_dsl_using_t_foreign_key) do
|
66
|
+
erbh(<<-ERB)
|
67
|
+
create_table "child", force: :cascade do |t|
|
68
|
+
t.integer "parent_id"
|
69
|
+
t.index ["parent_id"], name: "par_id"
|
70
|
+
t.foreign_key "parent", name: "child_ibfk_1"
|
71
|
+
end
|
72
|
+
|
73
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
74
|
+
end
|
75
|
+
ERB
|
76
|
+
end
|
77
|
+
|
78
|
+
before { subject.diff(actual_dsl).migrate }
|
79
|
+
subject { client }
|
80
|
+
|
81
|
+
it {
|
82
|
+
delta = subject.diff(expected_dsl_using_t_foreign_key)
|
83
|
+
expect(delta.differ?).to be_truthy
|
84
|
+
expect(subject.dump).to match_ruby actual_dsl
|
85
|
+
delta.migrate
|
86
|
+
expect(subject.dump).to match_ruby expected_dsl
|
87
|
+
}
|
88
|
+
|
89
|
+
it {
|
90
|
+
delta = client(bulk_change: true).diff(expected_dsl_using_t_foreign_key)
|
91
|
+
expect(delta.differ?).to be_truthy
|
92
|
+
expect(subject.dump).to match_ruby actual_dsl
|
93
|
+
expect(delta.script).to match_fuzzy <<-RUBY
|
94
|
+
add_foreign_key("child", "parent", **{:name=>"child_ibfk_1"})
|
95
|
+
RUBY
|
96
|
+
delta.migrate
|
97
|
+
expect(subject.dump).to match_ruby expected_dsl
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
46
101
|
context 'when create fk when create table' do
|
47
102
|
let(:dsl) do
|
48
103
|
erbh(<<-ERB)
|
@@ -57,6 +57,61 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
60
|
+
context 'when drop fk using `t.foreign_key`' do
|
61
|
+
let(:actual_dsl) do
|
62
|
+
erbh(<<-ERB)
|
63
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
64
|
+
end
|
65
|
+
|
66
|
+
create_table "child", force: :cascade do |t|
|
67
|
+
t.integer "parent_id"
|
68
|
+
t.index ["parent_id"], name: "par_id"
|
69
|
+
t.foreign_key "parent", name: "child_ibfk_1"
|
70
|
+
end
|
71
|
+
ERB
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:sorted_actual_dsl) do
|
75
|
+
expected_dsl + <<-RUBY
|
76
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
77
|
+
RUBY
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:expected_dsl) do
|
81
|
+
erbh(<<-ERB)
|
82
|
+
create_table "child", force: :cascade do |t|
|
83
|
+
t.integer "parent_id"
|
84
|
+
t.index ["parent_id"], name: "par_id"
|
85
|
+
end
|
86
|
+
|
87
|
+
create_table "parent", id: :integer, force: :cascade do |t|
|
88
|
+
end
|
89
|
+
ERB
|
90
|
+
end
|
91
|
+
|
92
|
+
before { subject.diff(actual_dsl).migrate }
|
93
|
+
subject { client }
|
94
|
+
|
95
|
+
it {
|
96
|
+
delta = subject.diff(expected_dsl)
|
97
|
+
expect(delta.differ?).to be_truthy
|
98
|
+
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
99
|
+
delta.migrate
|
100
|
+
expect(subject.dump).to match_ruby expected_dsl
|
101
|
+
}
|
102
|
+
|
103
|
+
it {
|
104
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
105
|
+
expect(delta.differ?).to be_truthy
|
106
|
+
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
107
|
+
expect(delta.script).to match_fuzzy <<-RUBY
|
108
|
+
remove_foreign_key("child", name: "child_ibfk_1")
|
109
|
+
RUBY
|
110
|
+
delta.migrate
|
111
|
+
expect(subject.dump).to match_ruby expected_dsl
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
60
115
|
context 'when drop fk when drop table' do
|
61
116
|
let(:dsl) do
|
62
117
|
erbh(<<-ERB)
|
@@ -186,6 +186,51 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
186
186
|
}
|
187
187
|
end
|
188
188
|
|
189
|
+
context 'when add unique index' do
|
190
|
+
let(:actual_dsl) do
|
191
|
+
erbh(<<-ERB)
|
192
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
193
|
+
t.date "birth_date", null: false
|
194
|
+
t.string "first_name", limit: 14, null: false
|
195
|
+
t.string "last_name", limit: 16, null: false
|
196
|
+
t.string "gender", limit: 1, null: false
|
197
|
+
t.date "hire_date", null: false
|
198
|
+
end
|
199
|
+
ERB
|
200
|
+
end
|
201
|
+
|
202
|
+
let(:expected_dsl) do
|
203
|
+
erbh(<<-ERB)
|
204
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
205
|
+
t.date "birth_date", null: false
|
206
|
+
t.string "first_name", limit: 14, null: false
|
207
|
+
t.string "last_name", limit: 16, null: false
|
208
|
+
t.string "gender", limit: 1, null: false
|
209
|
+
t.date "hire_date", null: false
|
210
|
+
t.index ["first_name"], name: "idx_first_name", unique: true
|
211
|
+
end
|
212
|
+
ERB
|
213
|
+
end
|
214
|
+
|
215
|
+
let(:alter_extra) { 'LOCK=DEFAULT, ALGORITHM=DEFAULT' }
|
216
|
+
|
217
|
+
before { subject.diff(actual_dsl).migrate }
|
218
|
+
subject { client }
|
219
|
+
|
220
|
+
it {
|
221
|
+
delta = subject.diff(expected_dsl)
|
222
|
+
expect(delta.differ?).to be_truthy
|
223
|
+
expect(subject.dump).to match_ruby actual_dsl
|
224
|
+
migrated, sql = delta.migrate(alter_extra: alter_extra, noop: true)
|
225
|
+
expect(migrated).to be_truthy
|
226
|
+
expect(sql).to match_fuzzy erbh(<<-SQL)
|
227
|
+
CREATE UNIQUE INDEX `idx_first_name` ON `employees` (`first_name`) LOCK=DEFAULT ALGORITHM=DEFAULT
|
228
|
+
SQL
|
229
|
+
delta.migrate(alter_extra: alter_extra)
|
230
|
+
expect(subject.dump).to match_ruby expected_dsl
|
231
|
+
}
|
232
|
+
end
|
233
|
+
|
189
234
|
context 'when drop index' do
|
190
235
|
let(:actual_dsl) do
|
191
236
|
erbh(<<-ERB)
|
@@ -5,7 +5,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
5
5
|
let(:dsl) do
|
6
6
|
erbh(<<-ERB)
|
7
7
|
create_table "salaries", id: false, force: :cascade do |t|
|
8
|
-
t.integer "
|
8
|
+
t.integer "emp_no_int", limit: 4, null: false
|
9
|
+
t.integer "emp_no_bigint5", limit: 5, null: false
|
10
|
+
t.integer "emp_no_bigint6", limit: 6, null: false
|
11
|
+
t.integer "emp_no_bigint7", limit: 7, null: false
|
12
|
+
t.integer "emp_no_bigint8", limit: 8, null: false
|
9
13
|
t.float "salary", <%= i cond('< 5.2.0.beta2', limit: 24) %>, null: false
|
10
14
|
t.date "from_date", null: false
|
11
15
|
t.date "to_date", null: false
|
@@ -17,7 +21,12 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
17
21
|
subject { client }
|
18
22
|
|
19
23
|
it {
|
20
|
-
expect(subject.dump).to match_ruby dsl
|
24
|
+
expect(subject.dump).to match_ruby dsl
|
25
|
+
.sub(/t.integer "emp_no_int", limit: 4/, 't.integer "emp_no_int"')
|
26
|
+
.sub(/t.integer "emp_no_bigint5", limit: 5/, 't.bigint "emp_no_bigint5"')
|
27
|
+
.sub(/t.integer "emp_no_bigint6", limit: 6/, 't.bigint "emp_no_bigint6"')
|
28
|
+
.sub(/t.integer "emp_no_bigint7", limit: 7/, 't.bigint "emp_no_bigint7"')
|
29
|
+
.sub(/t.integer "emp_no_bigint8", limit: 8/, 't.bigint "emp_no_bigint8"')
|
21
30
|
delta = subject.diff(dsl)
|
22
31
|
expect(delta.differ?).to be_falsey
|
23
32
|
}
|
@@ -157,4 +157,64 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
157
157
|
expect(subject.dump).to match_ruby expected_dsl
|
158
158
|
}
|
159
159
|
end
|
160
|
+
|
161
|
+
context 'when using index option' do
|
162
|
+
let(:dsl) do
|
163
|
+
erbh(<<-ERB)
|
164
|
+
create_table "clubs", force: :cascade do |t|
|
165
|
+
t.string "name", default: "", null: false, index: { unique: true }
|
166
|
+
end
|
167
|
+
|
168
|
+
create_table "titles", id: false, force: :cascade do |t|
|
169
|
+
t.integer "emp_no", null: false, index: { name: "emp_no" }
|
170
|
+
t.string "title", limit: 50, null: false
|
171
|
+
t.date "from_date", null: false
|
172
|
+
t.date "to_date"
|
173
|
+
end
|
174
|
+
ERB
|
175
|
+
end
|
176
|
+
|
177
|
+
let(:actual_dsl) do
|
178
|
+
erbh(<<-ERB)
|
179
|
+
create_table "clubs", force: :cascade do |t|
|
180
|
+
t.string "name", default: "", null: false
|
181
|
+
end
|
182
|
+
|
183
|
+
create_table "titles", id: false, force: :cascade do |t|
|
184
|
+
t.integer "emp_no", null: false
|
185
|
+
t.string "title", limit: 50, null: false
|
186
|
+
t.date "from_date", null: false
|
187
|
+
t.date "to_date"
|
188
|
+
end
|
189
|
+
ERB
|
190
|
+
end
|
191
|
+
|
192
|
+
let(:expected_dsl) do
|
193
|
+
erbh(<<-ERB)
|
194
|
+
create_table "clubs", force: :cascade do |t|
|
195
|
+
t.string "name", default: "", null: false
|
196
|
+
t.index ["name"], name: "index_clubs_on_name", unique: true
|
197
|
+
end
|
198
|
+
|
199
|
+
create_table "titles", id: false, force: :cascade do |t|
|
200
|
+
t.integer "emp_no", null: false
|
201
|
+
t.string "title", limit: 50, null: false
|
202
|
+
t.date "from_date", null: false
|
203
|
+
t.date "to_date"
|
204
|
+
t.index ["emp_no"], name: "emp_no"
|
205
|
+
end
|
206
|
+
ERB
|
207
|
+
end
|
208
|
+
|
209
|
+
before { subject.diff(actual_dsl).migrate }
|
210
|
+
subject { client }
|
211
|
+
|
212
|
+
it {
|
213
|
+
delta = subject.diff(dsl)
|
214
|
+
expect(delta.differ?).to be_truthy
|
215
|
+
expect(subject.dump).to match_ruby actual_dsl
|
216
|
+
delta.migrate
|
217
|
+
expect(subject.dump).to match_ruby expected_dsl
|
218
|
+
}
|
219
|
+
end
|
160
220
|
end
|
data/spec/spec_const.rb
CHANGED
@@ -5,7 +5,7 @@ TEST_MYSQL_PORT = ENV['MYSQL57'] == '1' ? 13_317 : 13_316
|
|
5
5
|
TEST_MYSQL_USER = 'root'
|
6
6
|
TEST_MYSQL_PASS = 'password'
|
7
7
|
|
8
|
-
MYSQL_CLI = "mysql -h #{TEST_MYSQL_HOST} -P #{TEST_MYSQL_PORT} -u #{TEST_MYSQL_USER} -p#{TEST_MYSQL_PASS} 2>/dev/null"
|
8
|
+
MYSQL_CLI = "mysql -h #{TEST_MYSQL_HOST} -P #{TEST_MYSQL_PORT} -u #{TEST_MYSQL_USER} -p#{TEST_MYSQL_PASS} --ssl-mode=DISABLED 2>/dev/null"
|
9
9
|
|
10
10
|
TEST_PG_HOST = ENV['DOCKER_HOST'] ? ENV['DOCKER_HOST'].gsub(%r{\Atcp://|:\d+\z}, '') : '127.0.0.1'
|
11
11
|
TEST_PG_PORT = 15_442
|
data/spec/spec_helper.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: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -204,14 +204,14 @@ dependencies:
|
|
204
204
|
requirements:
|
205
205
|
- - '='
|
206
206
|
- !ruby/object:Gem::Version
|
207
|
-
version: 1.
|
207
|
+
version: 1.9.1
|
208
208
|
type: :development
|
209
209
|
prerelease: false
|
210
210
|
version_requirements: !ruby/object:Gem::Requirement
|
211
211
|
requirements:
|
212
212
|
- - '='
|
213
213
|
- !ruby/object:Gem::Version
|
214
|
-
version: 1.
|
214
|
+
version: 1.9.1
|
215
215
|
- !ruby/object:Gem::Dependency
|
216
216
|
name: rubocop-rake
|
217
217
|
requirement: !ruby/object:Gem::Requirement
|
@@ -271,7 +271,7 @@ dependencies:
|
|
271
271
|
description: Ridgepole is a tool to manage DB schema. It defines DB schema using Rails
|
272
272
|
DSL, and updates DB schema according to DSL.
|
273
273
|
email:
|
274
|
-
- sugawara@
|
274
|
+
- sugawara@winebarrel.jp
|
275
275
|
executables:
|
276
276
|
- ridgepole
|
277
277
|
extensions: []
|
@@ -453,7 +453,7 @@ files:
|
|
453
453
|
- spec/spec_condition.rb
|
454
454
|
- spec/spec_const.rb
|
455
455
|
- spec/spec_helper.rb
|
456
|
-
homepage: https://github.com/
|
456
|
+
homepage: https://github.com/ridgepole/ridgepole
|
457
457
|
licenses:
|
458
458
|
- MIT
|
459
459
|
metadata: {}
|
@@ -472,7 +472,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
472
|
- !ruby/object:Gem::Version
|
473
473
|
version: '0'
|
474
474
|
requirements: []
|
475
|
-
rubygems_version: 3.
|
475
|
+
rubygems_version: 3.1.6
|
476
476
|
signing_key:
|
477
477
|
specification_version: 4
|
478
478
|
summary: Ridgepole is a tool to manage DB schema.
|