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,203 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when change 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"
|
105
|
+
end
|
106
|
+
|
107
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
108
|
+
|
109
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
110
|
+
t.date "birth_date", null: false
|
111
|
+
t.string "first_name", limit: 14, null: false
|
112
|
+
t.string "last_name", limit: 20, default: "XXX", null: false
|
113
|
+
t.date "hire_date", null: false
|
114
|
+
end
|
115
|
+
|
116
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
117
|
+
t.integer "emp_no", null: false
|
118
|
+
t.integer "salary", null: false
|
119
|
+
t.date "from_date", null: false
|
120
|
+
t.date "to_date", null: false
|
121
|
+
end
|
122
|
+
|
123
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
124
|
+
|
125
|
+
create_table "titles", id: false, force: :cascade do |t|
|
126
|
+
t.integer "emp_no", null: false
|
127
|
+
t.string "title", limit: 50, null: false
|
128
|
+
t.date "from_date", null: false
|
129
|
+
t.date "to_date"
|
130
|
+
end
|
131
|
+
|
132
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
133
|
+
RUBY
|
134
|
+
}
|
135
|
+
|
136
|
+
before { subject.diff(actual_dsl).migrate }
|
137
|
+
subject { client }
|
138
|
+
|
139
|
+
it {
|
140
|
+
delta = subject.diff(expected_dsl)
|
141
|
+
expect(delta.differ?).to be_truthy
|
142
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
143
|
+
delta.migrate
|
144
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/(\s*,\s*unsigned: false)?\s*,\s*null: true/, '')
|
145
|
+
}
|
146
|
+
|
147
|
+
it {
|
148
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, enable_mysql_unsigned: true)
|
149
|
+
expect(delta.differ?).to be_truthy
|
150
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
151
|
+
change_column("employee_clubs", "club_id", :integer, {:null=>false})
|
152
|
+
|
153
|
+
change_column("employees", "last_name", :string, {:limit=>16, :null=>false})
|
154
|
+
RUBY
|
155
|
+
}
|
156
|
+
|
157
|
+
it {
|
158
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
159
|
+
expect(delta.differ?).to be_truthy
|
160
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
161
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
162
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
163
|
+
t.change("club_id", :integer, {:null=>true, :default=>nil})
|
164
|
+
end
|
165
|
+
|
166
|
+
change_table("employees", {:bulk => true}) do |t|
|
167
|
+
t.change("last_name", :string, {:limit=>20, :default=>"XXX", :null=>false})
|
168
|
+
end
|
169
|
+
RUBY
|
170
|
+
delta.migrate
|
171
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/(\s*,\s*unsigned: false)?\s*,\s*null: true/, '')
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when string/text without limit (no change)' do
|
176
|
+
let(:actual_dsl) {
|
177
|
+
<<-RUBY
|
178
|
+
create_table "clubs", force: :cascade do |t|
|
179
|
+
t.string "name", default: "", null: false
|
180
|
+
t.text "desc"
|
181
|
+
end
|
182
|
+
RUBY
|
183
|
+
}
|
184
|
+
|
185
|
+
let(:expected_dsl) {
|
186
|
+
<<-RUBY
|
187
|
+
create_table "clubs", force: :cascade do |t|
|
188
|
+
t.string "name", default: "", null: false
|
189
|
+
t.text "desc"
|
190
|
+
end
|
191
|
+
RUBY
|
192
|
+
}
|
193
|
+
|
194
|
+
before { subject.diff(actual_dsl).migrate }
|
195
|
+
subject { client }
|
196
|
+
|
197
|
+
it {
|
198
|
+
delta = subject.diff(expected_dsl)
|
199
|
+
expect(delta.differ?).to be_falsey
|
200
|
+
}
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when change 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.integer "emp_no", null: false
|
88
|
+
t.string "dept_no", limit: 4, null: false
|
89
|
+
t.date "from_date", null: false
|
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", ["from_date"], 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_date", null: false
|
101
|
+
end
|
102
|
+
|
103
|
+
add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
|
104
|
+
add_index "dept_manager", ["from_date"], 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", ["from_date"], 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.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
147
|
+
delta.migrate
|
148
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
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
|
+
remove_index("dept_emp", {:name=>"idx_dept_emp_emp_no"})
|
156
|
+
add_index("dept_emp", ["emp_no"], {:name=>"idx_dept_emp_emp_no", :using=>:btree, :unique=>false})
|
157
|
+
|
158
|
+
remove_index("dept_manager", {:name=>"idx_dept_manager_emp_no"})
|
159
|
+
add_index("dept_manager", ["emp_no"], {:name=>"idx_dept_manager_emp_no", :using=>:btree, :unique=>false})
|
160
|
+
|
161
|
+
remove_index("salaries", {:name=>"idx_salaries_emp_no"})
|
162
|
+
add_index("salaries", ["emp_no"], {:name=>"idx_salaries_emp_no", :using=>:btree, :unique=>false})
|
163
|
+
RUBY
|
164
|
+
}
|
165
|
+
|
166
|
+
it {
|
167
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
168
|
+
expect(delta.differ?).to be_truthy
|
169
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
170
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
171
|
+
change_table("dept_emp", {:bulk => true}) do |t|
|
172
|
+
t.remove_index({:name=>"idx_dept_emp_emp_no"})
|
173
|
+
t.index(["from_date"], {:name=>"idx_dept_emp_emp_no", :using=>:btree, :unique=>false})
|
174
|
+
end
|
175
|
+
|
176
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
177
|
+
t.remove_index({:name=>"idx_dept_manager_emp_no"})
|
178
|
+
t.index(["from_date"], {:name=>"idx_dept_manager_emp_no", :using=>:btree, :unique=>false})
|
179
|
+
end
|
180
|
+
|
181
|
+
change_table("salaries", {:bulk => true}) do |t|
|
182
|
+
t.remove_index({:name=>"idx_salaries_emp_no"})
|
183
|
+
t.index(["from_date"], {:name=>"idx_salaries_emp_no", :using=>:btree, :unique=>false})
|
184
|
+
end
|
185
|
+
RUBY
|
186
|
+
|
187
|
+
expect {
|
188
|
+
delta.migrate
|
189
|
+
}.to_not raise_error
|
190
|
+
}
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when create 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
|
+
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(:actual_dsl) {
|
71
|
+
dsl.delete_create_table('clubs')
|
72
|
+
.delete_create_table('employee_clubs')
|
73
|
+
.delete_create_table('employees')
|
74
|
+
}
|
75
|
+
|
76
|
+
let(:expected_dsl) { dsl }
|
77
|
+
|
78
|
+
before { subject.diff(actual_dsl).migrate }
|
79
|
+
subject { client }
|
80
|
+
|
81
|
+
it {
|
82
|
+
delta = subject.diff(expected_dsl)
|
83
|
+
expect(delta.differ?).to be_truthy
|
84
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
85
|
+
delta.migrate
|
86
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
87
|
+
}
|
88
|
+
|
89
|
+
it {
|
90
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
91
|
+
expect(delta.differ?).to be_truthy
|
92
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
93
|
+
drop_table("clubs")
|
94
|
+
|
95
|
+
drop_table("employee_clubs")
|
96
|
+
|
97
|
+
drop_table("employees")
|
98
|
+
RUBY
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,185 @@
|
|
1
|
+
if postgresql?
|
2
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
3
|
+
context 'when drop 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
|
+
end
|
90
|
+
|
91
|
+
add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
|
92
|
+
add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
|
93
|
+
|
94
|
+
create_table "dept_manager", id: false, force: :cascade do |t|
|
95
|
+
t.string "dept_no", limit: 4, null: false
|
96
|
+
t.integer "emp_no", 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
|
+
end
|
106
|
+
|
107
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
|
108
|
+
|
109
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
110
|
+
t.date "birth_date", null: false
|
111
|
+
t.string "first_name", limit: 14, null: false
|
112
|
+
end
|
113
|
+
|
114
|
+
create_table "salaries", id: false, force: :cascade do |t|
|
115
|
+
t.integer "emp_no", null: false
|
116
|
+
t.integer "salary", null: false
|
117
|
+
t.date "from_date", null: false
|
118
|
+
t.date "to_date", null: false
|
119
|
+
end
|
120
|
+
|
121
|
+
add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
|
122
|
+
|
123
|
+
create_table "titles", id: false, force: :cascade do |t|
|
124
|
+
t.integer "emp_no", null: false
|
125
|
+
t.string "title", limit: 50, null: false
|
126
|
+
t.date "from_date", null: false
|
127
|
+
t.date "to_date"
|
128
|
+
end
|
129
|
+
|
130
|
+
add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
|
131
|
+
RUBY
|
132
|
+
}
|
133
|
+
|
134
|
+
before { subject.diff(actual_dsl).migrate }
|
135
|
+
subject { client }
|
136
|
+
|
137
|
+
it {
|
138
|
+
delta = subject.diff(expected_dsl)
|
139
|
+
expect(delta.differ?).to be_truthy
|
140
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
141
|
+
delta.migrate
|
142
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
143
|
+
}
|
144
|
+
|
145
|
+
it {
|
146
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
147
|
+
expect(delta.differ?).to be_truthy
|
148
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
149
|
+
add_column("dept_emp", "from_date", :date, {:null=>false, :after=>"dept_no"})
|
150
|
+
add_column("dept_emp", "to_date", :date, {:null=>false, :after=>"from_date"})
|
151
|
+
|
152
|
+
add_column("dept_manager", "from_date", :date, {:null=>false, :after=>"emp_no"})
|
153
|
+
add_column("dept_manager", "to_date", :date, {:null=>false, :after=>"from_date"})
|
154
|
+
|
155
|
+
add_column("employees", "last_name", :string, {:limit=>16, :null=>false, :after=>"first_name"})
|
156
|
+
add_column("employees", "hire_date", :date, {:null=>false, :after=>"last_name"})
|
157
|
+
RUBY
|
158
|
+
}
|
159
|
+
|
160
|
+
it {
|
161
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
162
|
+
expect(delta.differ?).to be_truthy
|
163
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
164
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
165
|
+
change_table("dept_emp", {:bulk => true}) do |t|
|
166
|
+
t.remove("from_date")
|
167
|
+
t.remove("to_date")
|
168
|
+
end
|
169
|
+
|
170
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
171
|
+
t.remove("from_date")
|
172
|
+
t.remove("to_date")
|
173
|
+
end
|
174
|
+
|
175
|
+
change_table("employees", {:bulk => true}) do |t|
|
176
|
+
t.remove("last_name")
|
177
|
+
t.remove("hire_date")
|
178
|
+
end
|
179
|
+
RUBY
|
180
|
+
delta.migrate
|
181
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
182
|
+
}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|