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,180 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when drop column and index' 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
|
+
add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
|
17
|
+
|
18
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
19
|
+
t.integer "emp_no", null: false
|
20
|
+
t.string "dept_no", limit: 4, null: false
|
21
|
+
t.date "from_date", null: false
|
22
|
+
t.date "to_date", null: false
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
26
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
27
|
+
|
28
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
29
|
+
t.string "dept_no", limit: 4, null: false
|
30
|
+
t.integer "emp_no", null: false
|
31
|
+
t.date "from_date", null: false
|
32
|
+
t.date "to_date", null: false
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
36
|
+
add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
|
37
|
+
|
38
|
+
create_table "employee_clubs", force: :cascade do |t|
|
39
|
+
t.integer "emp_no", null: false
|
40
|
+
t.integer "club_id", null: false
|
41
|
+
end
|
42
|
+
|
43
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
44
|
+
|
45
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
46
|
+
t.date "birth_date", null: false
|
47
|
+
t.string "first_name", limit: 14, null: false
|
48
|
+
t.string "last_name", limit: 16, null: false
|
49
|
+
t.date "hire_date", null: false
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
53
|
+
t.integer "emp_no", null: false
|
54
|
+
t.integer "salary", null: false
|
55
|
+
t.date "from_date", null: false
|
56
|
+
t.date "to_date", null: false
|
57
|
+
end
|
58
|
+
|
59
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
60
|
+
|
61
|
+
create_table "titles", id: false, force: :cascade do |t|
|
62
|
+
t.integer "emp_no", null: false
|
63
|
+
t.string "title", limit: 50, null: false
|
64
|
+
t.date "from_date", null: false
|
65
|
+
t.date "to_date"
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
69
|
+
RUBY
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:expected_dsl) {
|
73
|
+
<<-RUBY
|
74
|
+
create_table "clubs", force: :cascade do |t|
|
75
|
+
t.string "name", limit: 255, default: "", null: false
|
76
|
+
end
|
77
|
+
|
78
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
79
|
+
|
80
|
+
create_table "departments", primary_key: "dept_no", force: :cascade do |t|
|
81
|
+
t.string "dept_name", limit: 40, null: false
|
82
|
+
end
|
83
|
+
|
84
|
+
add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
|
85
|
+
|
86
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
87
|
+
t.string "dept_no", limit: 4, null: false
|
88
|
+
end
|
89
|
+
|
90
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_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
|
+
end
|
95
|
+
|
96
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
97
|
+
|
98
|
+
create_table "employee_clubs", force: :cascade do |t|
|
99
|
+
t.integer "emp_no", null: false
|
100
|
+
end
|
101
|
+
|
102
|
+
add_index "employee_clubs", ["emp_no"], name: "idx_employee_clubs_emp_no", using: :btree
|
103
|
+
|
104
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
105
|
+
t.date "birth_date", null: false
|
106
|
+
t.string "first_name", limit: 14, null: false
|
107
|
+
end
|
108
|
+
|
109
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
110
|
+
t.integer "emp_no", null: false
|
111
|
+
t.integer "salary", null: false
|
112
|
+
t.date "from_date", null: false
|
113
|
+
t.date "to_date", null: false
|
114
|
+
end
|
115
|
+
|
116
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
117
|
+
|
118
|
+
create_table "titles", id: false, force: :cascade do |t|
|
119
|
+
t.integer "emp_no", null: false
|
120
|
+
t.string "title", limit: 50, null: false
|
121
|
+
t.date "from_date", null: false
|
122
|
+
t.date "to_date"
|
123
|
+
end
|
124
|
+
|
125
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
126
|
+
RUBY
|
127
|
+
}
|
128
|
+
|
129
|
+
before { subject.diff(actual_dsl).migrate }
|
130
|
+
subject { client }
|
131
|
+
|
132
|
+
it {
|
133
|
+
delta = subject.diff(expected_dsl)
|
134
|
+
expect(delta.differ?).to be_truthy
|
135
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
136
|
+
delta.migrate
|
137
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
138
|
+
}
|
139
|
+
|
140
|
+
it {
|
141
|
+
delta = subject.diff(expected_dsl)
|
142
|
+
expect(delta.differ?).to be_truthy
|
143
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
144
|
+
delta.migrate(:noop => true)
|
145
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
146
|
+
}
|
147
|
+
|
148
|
+
it {
|
149
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
150
|
+
expect(delta.differ?).to be_truthy
|
151
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
152
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
153
|
+
change_table("dept_emp", {:bulk => true}) do |t|
|
154
|
+
t.remove("emp_no")
|
155
|
+
t.remove("from_date")
|
156
|
+
t.remove("to_date")
|
157
|
+
end
|
158
|
+
|
159
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
160
|
+
t.remove("emp_no")
|
161
|
+
t.remove("from_date")
|
162
|
+
t.remove("to_date")
|
163
|
+
end
|
164
|
+
|
165
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
166
|
+
t.remove("club_id")
|
167
|
+
t.index(["emp_no"], {:name=>"idx_employee_clubs_emp_no", :using=>:btree})
|
168
|
+
end
|
169
|
+
|
170
|
+
change_table("employees", {:bulk => true}) do |t|
|
171
|
+
t.remove("last_name")
|
172
|
+
t.remove("hire_date")
|
173
|
+
end
|
174
|
+
RUBY
|
175
|
+
delta.migrate
|
176
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
177
|
+
}
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when drop index' do
|
4
|
+
let(: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
|
+
add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
|
17
|
+
|
18
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
19
|
+
t.integer "emp_no", null: false
|
20
|
+
t.string "dept_no", limit: 4, null: false
|
21
|
+
t.date "from_date", null: false
|
22
|
+
t.date "to_date", null: false
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
26
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
27
|
+
|
28
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
29
|
+
t.string "dept_no", limit: 4, null: false
|
30
|
+
t.integer "emp_no", null: false
|
31
|
+
t.date "from_date", null: false
|
32
|
+
t.date "to_date", null: false
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
36
|
+
add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
|
37
|
+
|
38
|
+
create_table "employee_clubs", force: :cascade do |t|
|
39
|
+
t.integer "emp_no", null: false
|
40
|
+
t.integer "club_id", null: false
|
41
|
+
end
|
42
|
+
|
43
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
44
|
+
|
45
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
46
|
+
t.date "birth_date", null: false
|
47
|
+
t.string "first_name", limit: 14, null: false
|
48
|
+
t.string "last_name", limit: 16, null: false
|
49
|
+
t.date "hire_date", null: false
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
53
|
+
t.integer "emp_no", null: false
|
54
|
+
t.integer "salary", null: false
|
55
|
+
t.date "from_date", null: false
|
56
|
+
t.date "to_date", null: false
|
57
|
+
end
|
58
|
+
|
59
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
60
|
+
|
61
|
+
create_table "titles", id: false, force: :cascade do |t|
|
62
|
+
t.integer "emp_no", null: false
|
63
|
+
t.string "title", limit: 50, null: false
|
64
|
+
t.date "from_date", null: false
|
65
|
+
t.date "to_date"
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
69
|
+
RUBY
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:actual_dsl) { dsl }
|
73
|
+
|
74
|
+
let(:expected_dsl) {
|
75
|
+
dsl.delete_add_index('clubs', ['name']).
|
76
|
+
delete_add_index('employee_clubs', ['emp_no', 'club_id']).
|
77
|
+
delete_add_index('titles', ['emp_no'])
|
78
|
+
}
|
79
|
+
|
80
|
+
before { subject.diff(actual_dsl).migrate }
|
81
|
+
subject { client }
|
82
|
+
|
83
|
+
it {
|
84
|
+
delta = subject.diff(expected_dsl)
|
85
|
+
expect(delta.differ?).to be_truthy
|
86
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
87
|
+
delta.migrate
|
88
|
+
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
|
89
|
+
}
|
90
|
+
|
91
|
+
it {
|
92
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
93
|
+
expect(delta.differ?).to be_truthy
|
94
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
95
|
+
add_index("clubs", ["name"], {:name=>"idx_name", :unique=>true, :using=>:btree})
|
96
|
+
|
97
|
+
add_index("employee_clubs", ["emp_no", "club_id"], {:name=>"idx_employee_clubs_emp_no_club_id", :using=>:btree})
|
98
|
+
|
99
|
+
add_index("titles", ["emp_no"], {:name=>"idx_titles_emp_no", :using=>:btree})
|
100
|
+
RUBY
|
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 eq actual_dsl.strip_heredoc.strip
|
107
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
108
|
+
change_table("clubs", {:bulk => true}) do |t|
|
109
|
+
t.remove_index({:name=>"idx_name"})
|
110
|
+
end
|
111
|
+
|
112
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
113
|
+
t.remove_index({:name=>"idx_employee_clubs_emp_no_club_id"})
|
114
|
+
end
|
115
|
+
|
116
|
+
change_table("titles", {:bulk => true}) do |t|
|
117
|
+
t.remove_index({:name=>"idx_titles_emp_no"})
|
118
|
+
end
|
119
|
+
RUBY
|
120
|
+
delta.migrate
|
121
|
+
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
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when drop table' do
|
4
|
+
let(: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
|
+
add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
|
17
|
+
|
18
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
19
|
+
t.integer "emp_no", null: false
|
20
|
+
t.string "dept_no", limit: 4, null: false
|
21
|
+
t.date "from_date", null: false
|
22
|
+
t.date "to_date", null: false
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
26
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
27
|
+
|
28
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
29
|
+
t.string "dept_no", limit: 4, null: false
|
30
|
+
t.integer "emp_no", null: false
|
31
|
+
t.date "from_date", null: false
|
32
|
+
t.date "to_date", null: false
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
36
|
+
add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
|
37
|
+
|
38
|
+
create_table "employee_clubs", force: :cascade do |t|
|
39
|
+
t.integer "emp_no", null: false
|
40
|
+
t.integer "club_id", null: false
|
41
|
+
end
|
42
|
+
|
43
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
44
|
+
|
45
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
46
|
+
t.date "birth_date", null: false
|
47
|
+
t.string "first_name", limit: 14, null: false
|
48
|
+
t.string "last_name", limit: 16, null: false
|
49
|
+
t.date "hire_date", null: false
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
53
|
+
t.integer "emp_no", null: false
|
54
|
+
t.integer "salary", null: false
|
55
|
+
t.date "from_date", null: false
|
56
|
+
t.date "to_date", null: false
|
57
|
+
end
|
58
|
+
|
59
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
60
|
+
|
61
|
+
create_table "titles", id: false, force: :cascade do |t|
|
62
|
+
t.integer "emp_no", null: false
|
63
|
+
t.string "title", limit: 50, null: false
|
64
|
+
t.date "from_date", null: false
|
65
|
+
t.date "to_date"
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
69
|
+
RUBY
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:actual_dsl) { dsl }
|
73
|
+
|
74
|
+
let(:expected_dsl) {
|
75
|
+
dsl.delete_create_table('clubs')
|
76
|
+
.delete_create_table('employee_clubs')
|
77
|
+
.delete_create_table('employees')
|
78
|
+
}
|
79
|
+
|
80
|
+
before { subject.diff(actual_dsl).migrate }
|
81
|
+
subject { client }
|
82
|
+
|
83
|
+
it {
|
84
|
+
delta = subject.diff(expected_dsl)
|
85
|
+
expect(delta.differ?).to be_truthy
|
86
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
87
|
+
delta.migrate
|
88
|
+
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
|
89
|
+
}
|
90
|
+
|
91
|
+
it {
|
92
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
93
|
+
expect(delta.differ?).to be_truthy
|
94
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
95
|
+
create_table("clubs", {#{unsigned_if_enabled2('')}}) do |t|
|
96
|
+
t.string("name", {:limit=>255, :default=>"", :null=>false})
|
97
|
+
end
|
98
|
+
add_index("clubs", ["name"], {:name=>"idx_name", :unique=>true, :using=>:btree})
|
99
|
+
|
100
|
+
create_table("employee_clubs", {}) do |t|
|
101
|
+
t.integer("emp_no", {:null=>false})
|
102
|
+
t.integer("club_id", {:null=>false})
|
103
|
+
end
|
104
|
+
add_index("employee_clubs", ["emp_no", "club_id"], {:name=>"idx_employee_clubs_emp_no_club_id", :using=>:btree})
|
105
|
+
|
106
|
+
create_table("employees", {:primary_key=>"emp_no"}) do |t|
|
107
|
+
t.date("birth_date", {:null=>false})
|
108
|
+
t.string("first_name", {:limit=>14, :null=>false})
|
109
|
+
t.string("last_name", {:limit=>16, :null=>false})
|
110
|
+
t.date("hire_date", {:null=>false})
|
111
|
+
end
|
112
|
+
RUBY
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when rename 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
|
+
add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
|
17
|
+
|
18
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
19
|
+
t.integer "emp_no", null: false
|
20
|
+
t.string "dept_no", limit: 4, null: false
|
21
|
+
t.date "from_date", null: false
|
22
|
+
t.date "to_date", null: false
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
26
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
27
|
+
|
28
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
29
|
+
t.string "dept_no", limit: 4, null: false
|
30
|
+
t.integer "emp_no", null: false
|
31
|
+
t.date "from_date", null: false
|
32
|
+
t.date "to_date", null: false
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
36
|
+
add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
|
37
|
+
|
38
|
+
create_table "employee_clubs", force: :cascade do |t|
|
39
|
+
t.integer "emp_no", null: false
|
40
|
+
t.integer "club_id", null: false
|
41
|
+
end
|
42
|
+
|
43
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
44
|
+
|
45
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
46
|
+
t.date "birth_date", null: false
|
47
|
+
t.string "first_name", limit: 14, null: false
|
48
|
+
t.string "last_name", limit: 16, null: false
|
49
|
+
t.date "hire_date", null: false
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
53
|
+
t.integer "emp_no", null: false
|
54
|
+
t.integer "salary", null: false
|
55
|
+
t.date "from_date", null: false
|
56
|
+
t.date "to_date", null: false
|
57
|
+
end
|
58
|
+
|
59
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
60
|
+
|
61
|
+
create_table "titles", id: false, force: :cascade do |t|
|
62
|
+
t.integer "emp_no", null: false
|
63
|
+
t.string "title", limit: 50, null: false
|
64
|
+
t.date "from_date", null: false
|
65
|
+
t.date "to_date"
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
69
|
+
RUBY
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:expected_dsl) {
|
73
|
+
<<-RUBY
|
74
|
+
create_table "clubs", force: :cascade do |t|
|
75
|
+
t.string "name", limit: 255, default: "", null: false
|
76
|
+
end
|
77
|
+
|
78
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
79
|
+
|
80
|
+
create_table "departments", primary_key: "dept_no", force: :cascade do |t|
|
81
|
+
t.string "dept_name", limit: 40, null: false
|
82
|
+
end
|
83
|
+
|
84
|
+
add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
|
85
|
+
|
86
|
+
create_table "dept_emp", id: false, force: :cascade do |t|
|
87
|
+
t.integer "emp_no", null: false
|
88
|
+
t.string "dept_no", limit: 4, null: false
|
89
|
+
t.date "from_date2", null: false, renamed_from: 'from_date'
|
90
|
+
t.date "to_date", null: false
|
91
|
+
end
|
92
|
+
|
93
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
94
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
95
|
+
|
96
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
97
|
+
t.string "dept_no", limit: 4, null: false
|
98
|
+
t.integer "emp_no", null: false
|
99
|
+
t.date "from_date", null: false
|
100
|
+
t.date "to_date2", null: false, renamed_from: 'to_date'
|
101
|
+
end
|
102
|
+
|
103
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
104
|
+
add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
|
105
|
+
|
106
|
+
create_table "employee_clubs", force: :cascade do |t|
|
107
|
+
t.integer "emp_no", null: false
|
108
|
+
t.integer "club_id", null: false
|
109
|
+
end
|
110
|
+
|
111
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
112
|
+
|
113
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
114
|
+
t.date "birth_date", null: false
|
115
|
+
t.string "first_name", limit: 14, null: false
|
116
|
+
t.string "last_name", limit: 16, null: false
|
117
|
+
t.date "hire_date", null: false
|
118
|
+
end
|
119
|
+
|
120
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
121
|
+
t.integer "emp_no", null: false
|
122
|
+
t.integer "salary", null: false
|
123
|
+
t.date "from_date", null: false
|
124
|
+
t.date "to_date", null: false
|
125
|
+
end
|
126
|
+
|
127
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
128
|
+
|
129
|
+
create_table "titles", id: false, force: :cascade do |t|
|
130
|
+
t.integer "emp_no", null: false
|
131
|
+
t.string "title", limit: 50, null: false
|
132
|
+
t.date "from_date", null: false
|
133
|
+
t.date "to_date"
|
134
|
+
end
|
135
|
+
|
136
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
137
|
+
RUBY
|
138
|
+
}
|
139
|
+
|
140
|
+
before { subject.diff(actual_dsl).migrate }
|
141
|
+
subject { client }
|
142
|
+
|
143
|
+
it {
|
144
|
+
delta = subject.diff(expected_dsl)
|
145
|
+
expect(delta.differ?).to be_truthy
|
146
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
147
|
+
delta.migrate
|
148
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/\s*,\s*renamed_from:.*$/, '')
|
149
|
+
}
|
150
|
+
|
151
|
+
it {
|
152
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
153
|
+
expect(delta.differ?).to be_truthy
|
154
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
155
|
+
rename_column("dept_emp", "from_date2", "from_date")
|
156
|
+
|
157
|
+
rename_column("dept_manager", "to_date2", "to_date")
|
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("dept_emp", {:bulk => true}) do |t|
|
167
|
+
t.rename("from_date", "from_date2")
|
168
|
+
end
|
169
|
+
|
170
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
171
|
+
t.rename("to_date", "to_date2")
|
172
|
+
end
|
173
|
+
RUBY
|
174
|
+
delta.migrate
|
175
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/\s*,\s*renamed_from:.*$/, '')
|
176
|
+
}
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|