ridgepole 0.9.0 → 0.9.1
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 +3 -1
- data/lib/ridgepole/dsl_parser/table_definition.rb +4 -0
- 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/spec_const.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f3d6aadf39f73ef720c5f19404e303f98e75919164e51240570472d21c6c14e
|
4
|
+
data.tar.gz: 2e494165ba2dbd2c1a700ae3ebda831b43ca4439017a96513756f47d9f64f901
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b173d5e01ea89b0065dc617989cb89dd000050bf4aa973af74c714b55f7cbe414f932c6a44c1a9cc4dc10cf2e8db4ca590bd68ddc34176901700ab5c1d569e2
|
7
|
+
data.tar.gz: 20b1fa9092d28d119d9604ea3ffb7b11abe8080bb2edf6a6f0af88e095cb88724bb40836a59939f1eadee693386c0fbb64cf3876d56c4f3cdd4fd0f123a2b571
|
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,13 @@ 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))
|
138
140
|
</details>
|
139
141
|
|
140
142
|
**Notice**
|
@@ -120,6 +120,10 @@ module Ridgepole
|
|
120
120
|
@base.add_index(@table_name, name, options)
|
121
121
|
end
|
122
122
|
|
123
|
+
def foreign_key(name, options = {})
|
124
|
+
@base.add_foreign_key(@table_name, name, options)
|
125
|
+
end
|
126
|
+
|
123
127
|
def timestamps(*args)
|
124
128
|
options = { null: false }.merge(args.extract_options!)
|
125
129
|
column(:created_at, :datetime, options)
|
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', '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)
|
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.1
|
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-02-10 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
|
@@ -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.2
|
476
476
|
signing_key:
|
477
477
|
specification_version: 4
|
478
478
|
summary: Ridgepole is a tool to manage DB schema.
|