ridgepole 0.9.0.rc1 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +7 -20
- data/.rubocop.yml +5 -4
- data/README.md +14 -5
- 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/version.rb +1 -1
- data/ridgepole.gemspec +1 -1
- 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 +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b1fa89270221dcad6cdfa188a879de277c0ed1ea8672d2d9456b3057fe70ac1
|
4
|
+
data.tar.gz: 1d30c79ae7adf620347c70f769a12e0cb01e38fdf799cf6cbe67f952ab014d9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 853d1138335b2c697c7f84d1beceae743badacc2891fd05bb8d9349c7b8c10d763516d5d2c6e63d88a7f60d0c0f887270baa03738cc3496409bca6609990097c
|
7
|
+
data.tar.gz: f4b38e66c8a5295bdc7241a407b5a2c848a3558d6421a1cbe12520f5cd85aff08154783d353f0fc2d7ce4798f620e31e5b59fc31f2225ec4d52fefc33e8dec14
|
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
@@ -6,7 +6,6 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
6
6
|
(like Chef/Puppet)
|
7
7
|
|
8
8
|
[![Gem Version](https://badge.fury.io/rb/ridgepole.svg)](http://badge.fury.io/rb/ridgepole)
|
9
|
-
[![Unstable Version](https://img.shields.io/badge/unstable-0.9.0.beta-brightgreen.svg?longCache=true&style=flat)](https://rubygems.org/gems/ridgepole/versions/0.9.0.beta)
|
10
9
|
[![Build Status](https://github.com/winebarrel/ridgepole/workflows/test/badge.svg?branch=0.9)](https://github.com/winebarrel/ridgepole/actions)
|
11
10
|
[![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.9)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.9)
|
12
11
|
|
@@ -128,12 +127,22 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
128
127
|
* Support t.reference() foreign_key option ([pull#316](https://github.com/winebarrel/ridgepole/pull/316))
|
129
128
|
* `>= 0.8.12`
|
130
129
|
* Pluralize column specified by `references` ([pull#317](https://github.com/winebarrel/ridgepole/pull/317))
|
130
|
+
* `>= 0.8.13`
|
131
|
+
* Support `serial` and `bigserial` column types ([pull#321](https://github.com/winebarrel/ridgepole/pull/321))
|
131
132
|
* `>= 0.9.0`
|
132
|
-
* Remove `--mysql-alter
|
133
|
+
* Remove `--mysql-use-alter` option ([pull#330](https://github.com/winebarrel/ridgepole/pull/330))
|
133
134
|
* Add `--table-hash-options` option ([pull#331](https://github.com/winebarrel/ridgepole/pull/331))
|
134
135
|
* Support Rails 6.1 ([pull#323](https://github.com/winebarrel/ridgepole/pull/323))
|
135
136
|
* Disable Rails 5.0 support ([pull#335](https://github.com/winebarrel/ridgepole/pull/335))
|
136
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))
|
137
146
|
</details>
|
138
147
|
|
139
148
|
**Notice**
|
@@ -295,8 +304,8 @@ create_table "parent", force: :cascade do |t|
|
|
295
304
|
end
|
296
305
|
|
297
306
|
create_table "child", id: false, force: :cascade do |t|
|
298
|
-
t.
|
299
|
-
t.
|
307
|
+
t.bigint "id"
|
308
|
+
t.bigint "parent_id"
|
300
309
|
end
|
301
310
|
|
302
311
|
add_index "child", ["parent_id"], name: "par_ind", using: :btree
|
@@ -348,7 +357,7 @@ add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
|
348
357
|
|
349
358
|
execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
|
350
359
|
# Execute SQL only if there is no foreign key
|
351
|
-
c.raw_connection.query(<<-SQL).each.
|
360
|
+
c.raw_connection.query(<<-SQL).each.size.zero?
|
352
361
|
SELECT 1 FROM information_schema.key_column_usage
|
353
362
|
WHERE TABLE_SCHEMA = 'bookshelf'
|
354
363
|
AND CONSTRAINT_NAME = 'fk_author' LIMIT 1
|
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
@@ -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', '
|
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.4
|
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-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -202,16 +202,16 @@ dependencies:
|
|
202
202
|
name: rubocop
|
203
203
|
requirement: !ruby/object:Gem::Requirement
|
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
|
@@ -468,11 +468,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
468
468
|
version: 2.2.7
|
469
469
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
470
470
|
requirements:
|
471
|
-
- - "
|
471
|
+
- - ">="
|
472
472
|
- !ruby/object:Gem::Version
|
473
|
-
version:
|
473
|
+
version: '0'
|
474
474
|
requirements: []
|
475
|
-
rubygems_version: 3.
|
475
|
+
rubygems_version: 3.1.4
|
476
476
|
signing_key:
|
477
477
|
specification_version: 4
|
478
478
|
summary: Ridgepole is a tool to manage DB schema.
|