ridgepole 0.6.0.beta2 → 0.6.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +2 -0
- data/bin/ridgepole +16 -16
- data/lib/ridgepole/client.rb +6 -9
- data/lib/ridgepole/default_limit.rb +26 -0
- data/lib/ridgepole/delta.rb +2 -8
- data/lib/ridgepole/diff.rb +14 -10
- data/lib/ridgepole/version.rb +1 -1
- data/lib/ridgepole.rb +2 -10
- data/ridgepole.gemspec +1 -0
- data/spec/{bigint_pk → mysql/bigint_pk}/bigint_pkspec.rb +0 -0
- data/spec/{cli → mysql/cli}/config_spec.rb +3 -1
- data/spec/{cli → mysql/cli}/ridgepole_spec.rb +3 -0
- data/spec/{collation → mysql/collation}/collation_spec.rb +2 -0
- data/spec/{diff → mysql/diff}/diff2_spec.rb +2 -0
- data/spec/{diff → mysql/diff}/diff_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_class_method_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_some_tables_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_spec.rb +2 -0
- data/spec/{dump → mysql/dump}/dump_without_table_options_spec.rb +2 -0
- data/spec/{migrate_0 → mysql/fk}/migrate_change_fk_spec.rb +5 -3
- data/spec/{migrate_0 → mysql/fk}/migrate_create_fk_spec.rb +7 -5
- data/spec/{migrate_0 → mysql/fk}/migrate_drop_fk_spec.rb +6 -4
- data/spec/{migrate → mysql/migrate}/check_orphan_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_add_column2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_add_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column3_spec.rb +2 -0
- data/spec/mysql/migrate/migrate_change_column4_spec.rb +83 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column_float_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index3_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index4_spec.rb +2 -0
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +78 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_change_table_option_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_create_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_create_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_create_table_with_options_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_column_and_index_2_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_column_and_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_drop_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_duplicate_index_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_duplicate_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_empty_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_execute_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_merge_mode_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_noop_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_rename_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_rename_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_same_default_null_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_same_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_script_error_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_skip_rename_column_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_skip_rename_table_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_with_ignore_tables_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_with_pre_post_query_spec.rb +2 -0
- data/spec/{migrate → mysql/migrate}/migrate_with_tables_spec.rb +2 -0
- data/spec/{ridgepole_test_database.sql → mysql/ridgepole_test_database.sql} +0 -0
- data/spec/{ridgepole_test_tables.sql → mysql/ridgepole_test_tables.sql} +0 -0
- data/spec/postgresql/diff/diff_spec.rb +153 -0
- data/spec/postgresql/dump/dump_spec.rb +76 -0
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +62 -0
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +173 -0
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +114 -0
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +220 -0
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +203 -0
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +193 -0
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +103 -0
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +185 -0
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +180 -0
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +125 -0
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +116 -0
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +179 -0
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +199 -0
- data/spec/postgresql/migrate/migrate_same_spec.rb +84 -0
- data/spec/postgresql/ridgepole_test_database.sql +15 -0
- data/spec/postgresql/ridgepole_test_tables.sql +74 -0
- data/spec/spec_helper.rb +63 -7
- metadata +159 -104
@@ -0,0 +1,62 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when change fk' do
|
4
|
+
let(:actual_dsl) {
|
5
|
+
<<-RUBY
|
6
|
+
create_table "parent", force: :cascade do |t|
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table "child", force: :cascade do |t|
|
10
|
+
t.integer "parent_id"
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
14
|
+
|
15
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
|
16
|
+
RUBY
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:sorted_actual_dsl) {
|
20
|
+
<<-RUBY
|
21
|
+
create_table "child", force: :cascade do |t|
|
22
|
+
t.integer "parent_id"
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
26
|
+
|
27
|
+
create_table "parent", force: :cascade do |t|
|
28
|
+
end
|
29
|
+
|
30
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
|
31
|
+
RUBY
|
32
|
+
}
|
33
|
+
|
34
|
+
let(:expected_dsl) {
|
35
|
+
<<-RUBY
|
36
|
+
create_table "child", force: :cascade do |t|
|
37
|
+
t.integer "parent_id"
|
38
|
+
end
|
39
|
+
|
40
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
41
|
+
|
42
|
+
create_table "parent", force: :cascade do |t|
|
43
|
+
end
|
44
|
+
|
45
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
46
|
+
RUBY
|
47
|
+
}
|
48
|
+
|
49
|
+
before { subject.diff(actual_dsl).migrate }
|
50
|
+
|
51
|
+
subject { client(enable_foreigner: true) }
|
52
|
+
|
53
|
+
it {
|
54
|
+
delta = subject.diff(expected_dsl)
|
55
|
+
expect(delta.differ?).to be_truthy
|
56
|
+
expect(subject.dump.delete_empty_lines).to eq sorted_actual_dsl.strip_heredoc.strip.delete_empty_lines
|
57
|
+
delta.migrate
|
58
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when create fk' do
|
4
|
+
let(:actual_dsl) {
|
5
|
+
<<-RUBY
|
6
|
+
create_table "child", force: :cascade do |t|
|
7
|
+
t.integer "parent_id"
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
11
|
+
|
12
|
+
create_table "parent", force: :cascade do |t|
|
13
|
+
end
|
14
|
+
RUBY
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:expected_dsl) {
|
18
|
+
actual_dsl + (<<-RUBY)
|
19
|
+
|
20
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
21
|
+
RUBY
|
22
|
+
}
|
23
|
+
|
24
|
+
before { subject.diff(actual_dsl).migrate }
|
25
|
+
subject { client }
|
26
|
+
|
27
|
+
it {
|
28
|
+
delta = subject.diff(expected_dsl)
|
29
|
+
expect(delta.differ?).to be_truthy
|
30
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
31
|
+
delta.migrate
|
32
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
33
|
+
}
|
34
|
+
|
35
|
+
it {
|
36
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, default_int_limit: 4)
|
37
|
+
expect(delta.differ?).to be_truthy
|
38
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
39
|
+
remove_foreign_key("child", {:name=>"child_ibfk_1"})
|
40
|
+
RUBY
|
41
|
+
}
|
42
|
+
|
43
|
+
it {
|
44
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
45
|
+
expect(delta.differ?).to be_truthy
|
46
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
47
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
48
|
+
add_foreign_key("child", "parent", {:name=>"child_ibfk_1"})
|
49
|
+
RUBY
|
50
|
+
delta.migrate
|
51
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when create fk when create table' do
|
56
|
+
let(:dsl) {
|
57
|
+
<<-RUBY
|
58
|
+
# Define parent before child
|
59
|
+
create_table "parent", force: :cascade do |t|
|
60
|
+
end
|
61
|
+
|
62
|
+
create_table "child", force: :cascade do |t|
|
63
|
+
t.integer "parent_id", unsigned: true
|
64
|
+
end
|
65
|
+
|
66
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
67
|
+
|
68
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
69
|
+
RUBY
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:sorted_dsl) {
|
73
|
+
<<-RUBY
|
74
|
+
create_table "child", force: :cascade do |t|
|
75
|
+
t.integer "parent_id"
|
76
|
+
end
|
77
|
+
|
78
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
79
|
+
|
80
|
+
create_table "parent", force: :cascade do |t|
|
81
|
+
end
|
82
|
+
|
83
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
84
|
+
RUBY
|
85
|
+
}
|
86
|
+
|
87
|
+
before { client.diff('').migrate }
|
88
|
+
subject { client }
|
89
|
+
|
90
|
+
it {
|
91
|
+
delta = subject.diff(dsl)
|
92
|
+
expect(delta.differ?).to be_truthy
|
93
|
+
expect(subject.dump.strip).to eq ''
|
94
|
+
delta.migrate
|
95
|
+
expect(subject.dump.delete_empty_lines).to eq sorted_dsl.strip_heredoc.strip.delete_empty_lines
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'already defined' do
|
100
|
+
let(:dsl) {
|
101
|
+
<<-RUBY
|
102
|
+
# Define parent before child
|
103
|
+
create_table "parent", force: :cascade do |t|
|
104
|
+
end
|
105
|
+
|
106
|
+
create_table "child", force: :cascade do |t|
|
107
|
+
t.integer "parent_id", unsigned: true
|
108
|
+
end
|
109
|
+
|
110
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
111
|
+
|
112
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
113
|
+
|
114
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
115
|
+
RUBY
|
116
|
+
}
|
117
|
+
|
118
|
+
subject { client }
|
119
|
+
|
120
|
+
it {
|
121
|
+
expect {
|
122
|
+
subject.diff(dsl)
|
123
|
+
}.to raise_error('Foreign Key `child(child_ibfk_1)` already defined')
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'no name' do
|
128
|
+
let(:dsl) {
|
129
|
+
<<-RUBY
|
130
|
+
# Define parent before child
|
131
|
+
create_table "parent", force: :cascade do |t|
|
132
|
+
end
|
133
|
+
|
134
|
+
create_table "child", force: :cascade do |t|
|
135
|
+
t.integer "parent_id", unsigned: true
|
136
|
+
end
|
137
|
+
|
138
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
139
|
+
|
140
|
+
add_foreign_key "child", "parent"
|
141
|
+
RUBY
|
142
|
+
}
|
143
|
+
|
144
|
+
subject { client }
|
145
|
+
|
146
|
+
it {
|
147
|
+
expect {
|
148
|
+
subject.diff(dsl)
|
149
|
+
}.to raise_error('Foreign key name in `child` is undefined')
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'orphan fk' do
|
154
|
+
let(:dsl) {
|
155
|
+
<<-RUBY
|
156
|
+
# Define parent before child
|
157
|
+
create_table "parent", force: :cascade do |t|
|
158
|
+
end
|
159
|
+
|
160
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
161
|
+
RUBY
|
162
|
+
}
|
163
|
+
|
164
|
+
subject { client }
|
165
|
+
|
166
|
+
it {
|
167
|
+
expect {
|
168
|
+
subject.diff(dsl)
|
169
|
+
}.to raise_error('Table `child` to create the foreign key is not defined: child_ibfk_1')
|
170
|
+
}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when drop fk' do
|
4
|
+
let(:actual_dsl) {
|
5
|
+
<<-RUBY
|
6
|
+
create_table "parent", force: :cascade do |t|
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table "child", force: :cascade do |t|
|
10
|
+
t.integer "parent_id"
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
14
|
+
|
15
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
16
|
+
RUBY
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:sorted_actual_dsl) {
|
20
|
+
expected_dsl + (<<-RUBY)
|
21
|
+
|
22
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
23
|
+
RUBY
|
24
|
+
}
|
25
|
+
|
26
|
+
let(:expected_dsl) {
|
27
|
+
<<-RUBY
|
28
|
+
create_table "child", force: :cascade do |t|
|
29
|
+
t.integer "parent_id"
|
30
|
+
end
|
31
|
+
|
32
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
33
|
+
|
34
|
+
create_table "parent", force: :cascade do |t|
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
}
|
38
|
+
|
39
|
+
before { subject.diff(actual_dsl).migrate }
|
40
|
+
subject { client }
|
41
|
+
|
42
|
+
it {
|
43
|
+
delta = subject.diff(expected_dsl)
|
44
|
+
expect(delta.differ?).to be_truthy
|
45
|
+
expect(subject.dump).to eq sorted_actual_dsl.strip_heredoc.strip
|
46
|
+
delta.migrate
|
47
|
+
expect(subject.dump.each_line.select {|i| i !~ /\A\Z/ }.join).to eq expected_dsl.strip_heredoc.strip.each_line.select {|i| i !~ /\A\Z/ }.join
|
48
|
+
}
|
49
|
+
|
50
|
+
it {
|
51
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, default_int_limit: 4)
|
52
|
+
expect(delta.differ?).to be_truthy
|
53
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
54
|
+
add_foreign_key("child", "parent", {:name=>"child_ibfk_1"})
|
55
|
+
RUBY
|
56
|
+
}
|
57
|
+
|
58
|
+
it {
|
59
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
60
|
+
expect(delta.differ?).to be_truthy
|
61
|
+
expect(subject.dump).to eq sorted_actual_dsl.strip_heredoc.strip
|
62
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
63
|
+
remove_foreign_key("child", {:name=>"child_ibfk_1"})
|
64
|
+
RUBY
|
65
|
+
delta.migrate
|
66
|
+
expect(subject.dump.each_line.select {|i| i !~ /\A\Z/ }.join).to eq expected_dsl.strip_heredoc.strip.each_line.select {|i| i !~ /\A\Z/ }.join
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when drop fk when drop table' do
|
71
|
+
let(:dsl) {
|
72
|
+
<<-RUBY
|
73
|
+
create_table "parent", force: :cascade do |t|
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
create_table "child", force: :cascade do |t|
|
78
|
+
t.integer "parent_id", unsigned: true
|
79
|
+
end
|
80
|
+
|
81
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
82
|
+
|
83
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
84
|
+
RUBY
|
85
|
+
}
|
86
|
+
|
87
|
+
let(:sorted_dsl) {
|
88
|
+
<<-RUBY
|
89
|
+
create_table "child", force: :cascade do |t|
|
90
|
+
t.integer "parent_id"
|
91
|
+
end
|
92
|
+
|
93
|
+
add_index "child", ["parent_id"], name: "par_id", using: :btree
|
94
|
+
|
95
|
+
create_table "parent", force: :cascade do |t|
|
96
|
+
end
|
97
|
+
|
98
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
99
|
+
RUBY
|
100
|
+
}
|
101
|
+
|
102
|
+
before { subject.diff(dsl).migrate }
|
103
|
+
subject { client }
|
104
|
+
|
105
|
+
it {
|
106
|
+
delta = subject.diff('')
|
107
|
+
expect(delta.differ?).to be_truthy
|
108
|
+
expect(subject.dump).to eq sorted_dsl.strip_heredoc.strip
|
109
|
+
delta.migrate
|
110
|
+
expect(subject.dump.strip).to eq ''
|
111
|
+
}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when add column' do
|
4
|
+
let(:actual_dsl) {
|
5
|
+
<<-RUBY
|
6
|
+
create_table "clubs", force: :cascade do |t|
|
7
|
+
t.string "name", limit: 255, default: "", null: false
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
11
|
+
|
12
|
+
create_table "departments", primary_key: "dept_no", force: :cascade do |t|
|
13
|
+
t.string "dept_name", limit: 40, null: false
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
17
|
+
t.integer "emp_no", null: false
|
18
|
+
t.string "dept_no", limit: 4, null: false
|
19
|
+
t.date "from_date", null: false
|
20
|
+
t.date "to_date", null: false
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
24
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
25
|
+
|
26
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
27
|
+
t.string "dept_no", limit: 4, null: false
|
28
|
+
t.integer "emp_no", null: false
|
29
|
+
t.date "from_date", null: false
|
30
|
+
t.date "to_date", null: false
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
34
|
+
add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
|
35
|
+
|
36
|
+
create_table "employee_clubs", force: :cascade do |t|
|
37
|
+
t.integer "emp_no", null: false
|
38
|
+
t.integer "club_id", null: false
|
39
|
+
end
|
40
|
+
|
41
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
42
|
+
|
43
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
44
|
+
t.date "birth_date", null: false
|
45
|
+
t.string "first_name", limit: 14, null: false
|
46
|
+
t.string "last_name", limit: 16, null: false
|
47
|
+
t.date "hire_date", null: false
|
48
|
+
end
|
49
|
+
|
50
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
51
|
+
t.integer "emp_no", null: false
|
52
|
+
t.integer "salary", null: false
|
53
|
+
t.date "from_date", null: false
|
54
|
+
t.date "to_date", null: false
|
55
|
+
end
|
56
|
+
|
57
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
58
|
+
|
59
|
+
create_table "titles", id: false, force: :cascade do |t|
|
60
|
+
t.integer "emp_no", null: false
|
61
|
+
t.string "title", limit: 50, null: false
|
62
|
+
t.date "from_date", null: false
|
63
|
+
t.date "to_date"
|
64
|
+
end
|
65
|
+
|
66
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
67
|
+
RUBY
|
68
|
+
}
|
69
|
+
|
70
|
+
let(:expected_dsl) {
|
71
|
+
<<-RUBY
|
72
|
+
create_table "clubs", force: :cascade do |t|
|
73
|
+
t.string "name", limit: 255, default: "", null: false
|
74
|
+
end
|
75
|
+
|
76
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
77
|
+
|
78
|
+
create_table "departments", primary_key: "dept_no", force: :cascade do |t|
|
79
|
+
t.string "dept_name", limit: 40, null: false
|
80
|
+
end
|
81
|
+
|
82
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
83
|
+
t.integer "emp_no", null: false
|
84
|
+
t.string "dept_no", limit: 4, null: false
|
85
|
+
t.date "from_date", null: false
|
86
|
+
t.date "to_date", null: false
|
87
|
+
end
|
88
|
+
|
89
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
90
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
91
|
+
|
92
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
93
|
+
t.string "dept_no", limit: 4, null: false
|
94
|
+
t.integer "emp_no", null: false
|
95
|
+
t.date "from_date", null: false
|
96
|
+
t.date "to_date", null: false
|
97
|
+
end
|
98
|
+
|
99
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
100
|
+
add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
|
101
|
+
|
102
|
+
create_table "employee_clubs", force: :cascade do |t|
|
103
|
+
t.integer "emp_no", null: false
|
104
|
+
t.integer "club_id", null: false
|
105
|
+
t.string "any_col", limit: 255, null: false
|
106
|
+
end
|
107
|
+
|
108
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
109
|
+
|
110
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
111
|
+
t.date "birth_date", null: false
|
112
|
+
t.string "first_name", limit: 14, null: false
|
113
|
+
t.string "last_name", limit: 16, null: false
|
114
|
+
t.date "hire_date", null: false
|
115
|
+
t.integer "age", null: false
|
116
|
+
t.date "updated_at"
|
117
|
+
end
|
118
|
+
|
119
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
120
|
+
t.integer "emp_no", null: false
|
121
|
+
t.integer "salary", null: false
|
122
|
+
t.date "from_date", null: false
|
123
|
+
t.date "to_date", null: false
|
124
|
+
end
|
125
|
+
|
126
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
127
|
+
|
128
|
+
create_table "titles", id: false, force: :cascade do |t|
|
129
|
+
t.integer "emp_no", null: false
|
130
|
+
t.string "title", limit: 50, null: false
|
131
|
+
t.date "from_date", null: false
|
132
|
+
t.date "to_date"
|
133
|
+
end
|
134
|
+
|
135
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
136
|
+
RUBY
|
137
|
+
}
|
138
|
+
|
139
|
+
before { subject.diff(actual_dsl).migrate }
|
140
|
+
subject { client }
|
141
|
+
|
142
|
+
it {
|
143
|
+
delta = subject.diff(expected_dsl)
|
144
|
+
expect(delta.differ?).to be_truthy
|
145
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
146
|
+
delta.migrate
|
147
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
148
|
+
}
|
149
|
+
|
150
|
+
it {
|
151
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
152
|
+
expect(delta.differ?).to be_truthy
|
153
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
154
|
+
remove_column("employee_clubs", "any_col")
|
155
|
+
|
156
|
+
remove_column("employees", "age")
|
157
|
+
remove_column("employees", "updated_at")
|
158
|
+
RUBY
|
159
|
+
}
|
160
|
+
|
161
|
+
it {
|
162
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
163
|
+
expect(delta.differ?).to be_truthy
|
164
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
165
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
166
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
167
|
+
t.column("any_col", :string, {:limit=>255, :null=>false, :after=>"club_id"})
|
168
|
+
end
|
169
|
+
|
170
|
+
change_table("employees", {:bulk => true}) do |t|
|
171
|
+
t.column("age", :integer, {:null=>false, :after=>"hire_date"})
|
172
|
+
t.column("updated_at", :date, {:after=>"age"})
|
173
|
+
end
|
174
|
+
RUBY
|
175
|
+
delta.migrate
|
176
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'when add column (int/noop)' do
|
181
|
+
let(:actual_dsl) {
|
182
|
+
<<-RUBY
|
183
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
184
|
+
t.integer "emp_no", null: false
|
185
|
+
t.string "dept_no", limit: 4, null: false
|
186
|
+
t.date "from_date", null: false
|
187
|
+
t.date "to_date", null: false
|
188
|
+
end
|
189
|
+
RUBY
|
190
|
+
}
|
191
|
+
|
192
|
+
let(:expected_dsl) {
|
193
|
+
<<-RUBY
|
194
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
195
|
+
t.integer "emp_no", null: false
|
196
|
+
t.integer "emp_no2", null: false
|
197
|
+
t.string "dept_no", limit: 4, null: false
|
198
|
+
t.date "from_date", null: false
|
199
|
+
t.date "to_date", null: false
|
200
|
+
end
|
201
|
+
RUBY
|
202
|
+
}
|
203
|
+
|
204
|
+
before { subject.diff(actual_dsl).migrate }
|
205
|
+
subject { client }
|
206
|
+
|
207
|
+
it {
|
208
|
+
delta = subject.diff(expected_dsl)
|
209
|
+
expect(delta.differ?).to be_truthy
|
210
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
211
|
+
migrated, sql = delta.migrate(:noop => true)
|
212
|
+
expect(migrated).to be_truthy
|
213
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
214
|
+
|
215
|
+
sql = sql.each_line.map {|i| i.strip }.join("\n")
|
216
|
+
expect(sql).to eq("ALTER TABLE \"dept_emp\" ADD \"emp_no2\" integer NOT NULL")
|
217
|
+
}
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|