ridgepole 0.7.3.beta → 0.7.3.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +38 -0
- data/Appraisals +2 -2
- data/README.md +3 -9
- data/Rakefile +7 -1
- data/bin/ridgepole +97 -108
- data/gemfiles/activerecord_5.2.gemfile +1 -1
- data/lib/ridgepole/cli/config.rb +43 -43
- data/lib/ridgepole/client.rb +65 -63
- data/lib/ridgepole/default_limit.rb +26 -24
- data/lib/ridgepole/delta.rb +367 -369
- data/lib/ridgepole/diff.rb +366 -377
- data/lib/ridgepole/dsl_parser.rb +22 -20
- data/lib/ridgepole/dsl_parser/context.rb +95 -93
- data/lib/ridgepole/dsl_parser/table_definition.rb +125 -123
- data/lib/ridgepole/dumper.rb +73 -71
- data/lib/ridgepole/execute_expander.rb +55 -55
- data/lib/ridgepole/ext/abstract_mysql_adapter/dump_auto_increment.rb +3 -3
- data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +1 -1
- data/lib/ridgepole/ext/pp_sort_hash.rb +14 -14
- data/lib/ridgepole/ext/schema_dumper.rb +1 -1
- data/lib/ridgepole/external_sql_executer.rb +20 -20
- data/lib/ridgepole/logger.rb +17 -15
- data/lib/ridgepole/migration_ext.rb +6 -8
- data/lib/ridgepole/schema_statements_ext.rb +3 -3
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +11 -10
- data/spec/cli_helper.rb +2 -2
- data/spec/erb_helper.rb +6 -2
- data/spec/hide_pending_formatter.rb +5 -4
- data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +8 -8
- data/spec/mysql/bigint_pk/bigint_pk_spec.rb +8 -8
- data/spec/mysql/bigint_pk/int_pk_spec.rb +13 -13
- data/spec/mysql/cli/config_spec.rb +52 -53
- data/spec/mysql/cli/ridgepole_spec.rb +111 -111
- data/spec/mysql/collation/collation_spec.rb +39 -39
- data/spec/mysql/comment/comment_spec.rb +36 -36
- data/spec/mysql/default_lambda/default_lambda_spec.rb +30 -30
- data/spec/mysql/diff/diff2_spec.rb +18 -18
- data/spec/mysql/diff/diff_spec.rb +11 -11
- data/spec/mysql/dump/dump_class_method_spec.rb +2 -2
- data/spec/mysql/dump/dump_some_tables_spec.rb +14 -14
- data/spec/mysql/dump/dump_spec.rb +2 -2
- data/spec/mysql/dump/dump_unknown_column_type_spec.rb +3 -3
- data/spec/mysql/dump/dump_without_table_options_spec.rb +8 -8
- data/spec/mysql/fk/migrate_change_fk_spec.rb +40 -40
- data/spec/mysql/fk/migrate_create_fk_spec.rb +40 -40
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +60 -60
- data/spec/mysql/migrate/check_orphan_index_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_add_column2_spec.rb +43 -43
- data/spec/mysql/migrate/migrate_add_column_order_spec.rb +50 -50
- data/spec/mysql/migrate/migrate_add_column_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_change_column2_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +60 -60
- data/spec/mysql/migrate/migrate_change_column4_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_change_column5_spec.rb +24 -24
- data/spec/mysql/migrate/migrate_change_column6_spec.rb +40 -40
- data/spec/mysql/migrate/migrate_change_column7_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_change_column8_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_change_column_default_spec.rb +48 -48
- data/spec/mysql/migrate/migrate_change_column_float_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_change_column_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_change_index2_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_index3_spec.rb +43 -43
- data/spec/mysql/migrate/migrate_change_index4_spec.rb +24 -24
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_change_index6_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_change_index7_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_index8_spec.rb +20 -20
- data/spec/mysql/migrate/migrate_change_index_spec.rb +17 -17
- data/spec/mysql/migrate/migrate_change_table_comment_spec.rb +10 -10
- data/spec/mysql/migrate/migrate_change_table_option_spec.rb +18 -18
- data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +37 -37
- data/spec/mysql/migrate/migrate_create_index2_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_create_index_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_create_table_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +10 -10
- data/spec/mysql/migrate/migrate_drop_column_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_drop_index_spec.rb +11 -11
- data/spec/mysql/migrate/migrate_drop_table_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +6 -6
- data/spec/mysql/migrate/migrate_empty_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_execute_spec.rb +55 -55
- data/spec/mysql/migrate/migrate_log_file_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_merge_mode_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_noop_spec.rb +19 -19
- data/spec/mysql/migrate/migrate_primary_key_spec.rb +18 -18
- data/spec/mysql/migrate/migrate_rename_column_spec.rb +17 -17
- data/spec/mysql/migrate/migrate_rename_table_spec.rb +26 -26
- data/spec/mysql/migrate/migrate_same_default_null_spec.rb +16 -16
- data/spec/mysql/migrate/migrate_same_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_script_error_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +8 -8
- data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +9 -9
- data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +64 -64
- data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +12 -12
- data/spec/mysql/migrate/migrate_with_tables_spec.rb +29 -29
- data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +18 -18
- data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +8 -8
- data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +8 -8
- data/spec/mysql/text_blob_types/text_blob_types_spec.rb +8 -8
- data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +12 -12
- data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +30 -30
- data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +22 -22
- data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +7 -7
- data/spec/mysql57/json/add_json_column_spec.rb +8 -8
- data/spec/mysql57/json/change_json_column_spec.rb +24 -24
- data/spec/mysql57/json/drop_json_column_spec.rb +8 -8
- data/spec/mysql57/virtual/add_virtual_column_spec.rb +9 -9
- data/spec/mysql57/virtual/change_virtual_column_spec.rb +9 -9
- data/spec/mysql57/virtual/drop_virtual_column_spec.rb +9 -9
- data/spec/postgresql/diff/diff_spec.rb +18 -18
- data/spec/postgresql/dump/dump_spec.rb +2 -2
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +24 -24
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +40 -40
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +44 -44
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +21 -21
- data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +2 -2
- data/spec/postgresql/migrate/migrate_bigint_spec.rb +12 -12
- data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +19 -19
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +13 -13
- data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +19 -19
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +18 -18
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +11 -11
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +12 -12
- data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +11 -11
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +8 -8
- data/spec/postgresql/migrate/migrate_primary_key_spec.rb +97 -0
- data/spec/postgresql/migrate/migrate_references_spec.rb +24 -24
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +11 -11
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +16 -16
- data/spec/postgresql/migrate/migrate_same_spec.rb +4 -4
- data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +12 -12
- data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +30 -30
- data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +22 -22
- data/spec/processing_for_travis.rb +1 -1
- data/spec/spec_condition.rb +2 -2
- data/spec/spec_const.rb +9 -9
- data/spec/spec_helper.rb +21 -23
- metadata +54 -37
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when drop column and index (2)' do
|
3
|
-
let(:actual_dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:actual_dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "clubs", force: :cascade do |t|
|
6
6
|
t.string "name", default: "", null: false
|
7
7
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -59,11 +59,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
59
59
|
t.date "to_date"
|
60
60
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
61
61
|
end
|
62
|
-
|
63
|
-
|
62
|
+
ERB
|
63
|
+
end
|
64
64
|
|
65
|
-
let(:expected_dsl)
|
66
|
-
erbh(<<-
|
65
|
+
let(:expected_dsl) do
|
66
|
+
erbh(<<-ERB)
|
67
67
|
create_table "clubs", force: :cascade do |t|
|
68
68
|
t.string "name", default: "", null: false
|
69
69
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -113,8 +113,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
113
113
|
t.date "to_date"
|
114
114
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
115
115
|
end
|
116
|
-
|
117
|
-
|
116
|
+
ERB
|
117
|
+
end
|
118
118
|
|
119
119
|
before { subject.diff(actual_dsl).migrate }
|
120
120
|
subject { client }
|
@@ -131,7 +131,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
131
131
|
delta = subject.diff(expected_dsl)
|
132
132
|
expect(delta.differ?).to be_truthy
|
133
133
|
expect(subject.dump).to match_ruby actual_dsl
|
134
|
-
delta.migrate(:
|
134
|
+
delta.migrate(noop: true)
|
135
135
|
expect(subject.dump).to match_ruby actual_dsl
|
136
136
|
}
|
137
137
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when drop column and index' do
|
3
|
-
let(:actual_dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:actual_dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "clubs", force: :cascade do |t|
|
6
6
|
t.string "name", default: "", null: false
|
7
7
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -59,11 +59,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
59
59
|
t.date "to_date"
|
60
60
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
61
61
|
end
|
62
|
-
|
63
|
-
|
62
|
+
ERB
|
63
|
+
end
|
64
64
|
|
65
|
-
let(:expected_dsl)
|
66
|
-
erbh(<<-
|
65
|
+
let(:expected_dsl) do
|
66
|
+
erbh(<<-ERB)
|
67
67
|
create_table "clubs", force: :cascade do |t|
|
68
68
|
t.string "name", default: "", null: false
|
69
69
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -109,8 +109,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
109
109
|
t.date "to_date"
|
110
110
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
111
111
|
end
|
112
|
-
|
113
|
-
|
112
|
+
ERB
|
113
|
+
end
|
114
114
|
|
115
115
|
before { subject.diff(actual_dsl).migrate }
|
116
116
|
subject { client }
|
@@ -127,15 +127,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
127
127
|
delta = subject.diff(expected_dsl)
|
128
128
|
expect(delta.differ?).to be_truthy
|
129
129
|
expect(subject.dump).to match_ruby actual_dsl
|
130
|
-
delta.migrate(:
|
130
|
+
delta.migrate(noop: true)
|
131
131
|
expect(subject.dump).to match_ruby actual_dsl
|
132
132
|
}
|
133
133
|
|
134
134
|
it {
|
135
|
-
delta = client(:
|
135
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
136
136
|
expect(delta.differ?).to be_truthy
|
137
137
|
expect(subject.dump).to match_ruby actual_dsl
|
138
|
-
expect(delta.script).to match_fuzzy <<-
|
138
|
+
expect(delta.script).to match_fuzzy <<-RUBY
|
139
139
|
change_table("dept_emp", {:bulk => true}) do |t|
|
140
140
|
t.remove("emp_no")
|
141
141
|
t.remove("from_date")
|
@@ -157,7 +157,7 @@ change_table("employees", {:bulk => true}) do |t|
|
|
157
157
|
t.remove("gender")
|
158
158
|
t.remove("hire_date")
|
159
159
|
end
|
160
|
-
|
160
|
+
RUBY
|
161
161
|
delta.migrate
|
162
162
|
expect(subject.dump).to match_ruby expected_dsl
|
163
163
|
}
|
@@ -1,22 +1,22 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when drop column and unique index' do
|
3
|
-
let(:actual_dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:actual_dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
6
6
|
t.string "first_name", limit: 14, null: false
|
7
7
|
t.string "last_name", limit: 16, null: false
|
8
8
|
t.index ["first_name", "last_name"], name: "first_name_last_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
9
9
|
end
|
10
|
-
|
11
|
-
|
10
|
+
ERB
|
11
|
+
end
|
12
12
|
|
13
|
-
let(:expected_dsl)
|
14
|
-
erbh(<<-
|
13
|
+
let(:expected_dsl) do
|
14
|
+
erbh(<<-ERB)
|
15
15
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
16
16
|
t.string "first_name", limit: 14, null: false
|
17
17
|
end
|
18
|
-
|
19
|
-
|
18
|
+
ERB
|
19
|
+
end
|
20
20
|
|
21
21
|
before do
|
22
22
|
subject.diff(actual_dsl).migrate
|
@@ -27,7 +27,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
27
27
|
('Taro', 'Yamada'), ('Taro', 'Sato')
|
28
28
|
;
|
29
29
|
SQL
|
30
|
-
|
30
|
+
)
|
31
31
|
end
|
32
32
|
subject { client }
|
33
33
|
|
@@ -43,7 +43,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
43
43
|
delta = subject.diff(expected_dsl)
|
44
44
|
expect(delta.differ?).to be_truthy
|
45
45
|
expect(subject.dump).to match_ruby actual_dsl
|
46
|
-
delta.migrate(:
|
46
|
+
delta.migrate(noop: true)
|
47
47
|
expect(subject.dump).to match_ruby actual_dsl
|
48
48
|
}
|
49
49
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when drop column' do
|
3
|
-
let(:actual_dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:actual_dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "clubs", force: :cascade do |t|
|
6
6
|
t.string "name", default: "", null: false
|
7
7
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -59,11 +59,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
59
59
|
t.date "to_date"
|
60
60
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
61
61
|
end
|
62
|
-
|
63
|
-
|
62
|
+
ERB
|
63
|
+
end
|
64
64
|
|
65
|
-
let(:expected_dsl)
|
66
|
-
erbh(<<-
|
65
|
+
let(:expected_dsl) do
|
66
|
+
erbh(<<-ERB)
|
67
67
|
create_table "clubs", force: :cascade do |t|
|
68
68
|
t.string "name", default: "", null: false
|
69
69
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -114,8 +114,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
114
114
|
t.date "to_date"
|
115
115
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
116
116
|
end
|
117
|
-
|
118
|
-
|
117
|
+
ERB
|
118
|
+
end
|
119
119
|
|
120
120
|
before { subject.diff(actual_dsl).migrate }
|
121
121
|
subject { client }
|
@@ -129,10 +129,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
129
129
|
}
|
130
130
|
|
131
131
|
it {
|
132
|
-
delta = client(:
|
132
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
133
133
|
expect(delta.differ?).to be_truthy
|
134
134
|
expect(subject.dump).to match_ruby actual_dsl
|
135
|
-
expect(delta.script).to match_fuzzy <<-
|
135
|
+
expect(delta.script).to match_fuzzy <<-RUBY
|
136
136
|
change_table("dept_emp", {:bulk => true}) do |t|
|
137
137
|
t.remove("from_date")
|
138
138
|
t.remove("to_date")
|
@@ -148,7 +148,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
148
148
|
t.remove("gender")
|
149
149
|
t.remove("hire_date")
|
150
150
|
end
|
151
|
-
|
151
|
+
RUBY
|
152
152
|
delta.migrate
|
153
153
|
expect(subject.dump).to match_ruby expected_dsl
|
154
154
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when drop index' do
|
3
|
-
let(:dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "clubs", force: :cascade do |t|
|
6
6
|
t.string "name", default: "", null: false
|
7
7
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -59,13 +59,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
59
59
|
t.date "to_date"
|
60
60
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
61
61
|
end
|
62
|
-
|
63
|
-
|
62
|
+
ERB
|
63
|
+
end
|
64
64
|
|
65
65
|
let(:actual_dsl) { dsl }
|
66
66
|
|
67
|
-
let(:expected_dsl)
|
68
|
-
erbh(<<-
|
67
|
+
let(:expected_dsl) do
|
68
|
+
erbh(<<-ERB)
|
69
69
|
create_table "clubs", force: :cascade do |t|
|
70
70
|
t.string "name", default: "", null: false
|
71
71
|
end
|
@@ -120,8 +120,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
120
120
|
t.date "from_date", null: false
|
121
121
|
t.date "to_date"
|
122
122
|
end
|
123
|
-
|
124
|
-
|
123
|
+
ERB
|
124
|
+
end
|
125
125
|
|
126
126
|
before { subject.diff(actual_dsl).migrate }
|
127
127
|
subject { client }
|
@@ -135,10 +135,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
135
135
|
}
|
136
136
|
|
137
137
|
it {
|
138
|
-
delta = client(:
|
138
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
139
139
|
expect(delta.differ?).to be_truthy
|
140
140
|
expect(subject.dump).to match_ruby actual_dsl
|
141
|
-
expect(delta.script).to match_fuzzy <<-
|
141
|
+
expect(delta.script).to match_fuzzy <<-RUBY
|
142
142
|
change_table("clubs", {:bulk => true}) do |t|
|
143
143
|
t.remove_index({:name=>"idx_name"})
|
144
144
|
end
|
@@ -150,7 +150,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
150
150
|
change_table("titles", {:bulk => true}) do |t|
|
151
151
|
t.remove_index({:name=>"emp_no"})
|
152
152
|
end
|
153
|
-
|
153
|
+
RUBY
|
154
154
|
delta.migrate
|
155
155
|
expect(subject.dump).to match_ruby expected_dsl
|
156
156
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when drop table' do
|
3
|
-
let(:dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "clubs", force: :cascade do |t|
|
6
6
|
t.string "name", default: "", null: false
|
7
7
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -59,13 +59,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
59
59
|
t.date "to_date"
|
60
60
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
61
61
|
end
|
62
|
-
|
63
|
-
|
62
|
+
ERB
|
63
|
+
end
|
64
64
|
|
65
65
|
let(:actual_dsl) { dsl }
|
66
66
|
|
67
|
-
let(:expected_dsl)
|
68
|
-
erbh(<<-
|
67
|
+
let(:expected_dsl) do
|
68
|
+
erbh(<<-ERB)
|
69
69
|
create_table "departments", primary_key: "dept_no", force: :cascade do |t|
|
70
70
|
t.string "dept_name", limit: 40, null: false
|
71
71
|
t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -104,8 +104,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
104
104
|
t.date "to_date"
|
105
105
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
106
106
|
end
|
107
|
-
|
108
|
-
|
107
|
+
ERB
|
108
|
+
end
|
109
109
|
|
110
110
|
before { subject.diff(actual_dsl).migrate }
|
111
111
|
subject { client }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when index already defined' do
|
3
|
-
let(:dsl)
|
4
|
-
<<-
|
3
|
+
let(:dsl) do
|
4
|
+
<<-RUBY
|
5
5
|
create_table "salaries", id: false, force: :cascade do |t|
|
6
6
|
t.integer "emp_no", null: false
|
7
7
|
t.integer "salary", null: false
|
@@ -11,15 +11,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
11
11
|
|
12
12
|
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
13
13
|
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
14
|
-
|
15
|
-
|
14
|
+
RUBY
|
15
|
+
end
|
16
16
|
|
17
17
|
subject { client }
|
18
18
|
|
19
19
|
it {
|
20
|
-
expect
|
20
|
+
expect do
|
21
21
|
subject.diff(dsl)
|
22
|
-
|
22
|
+
end.to raise_error('Index `salaries(emp_no)` already defined')
|
23
23
|
}
|
24
24
|
end
|
25
25
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when table already defined' do
|
3
|
-
let(:dsl)
|
4
|
-
<<-
|
3
|
+
let(:dsl) do
|
4
|
+
<<-RUBY
|
5
5
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
6
6
|
t.date "birth_date", null: false
|
7
7
|
t.string "first_name", limit: 14, null: false
|
@@ -21,15 +21,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
21
21
|
t.integer "age", unsigned: true, null: false
|
22
22
|
t.date "updated_at"
|
23
23
|
end
|
24
|
-
|
25
|
-
|
24
|
+
RUBY
|
25
|
+
end
|
26
26
|
|
27
27
|
subject { client }
|
28
28
|
|
29
29
|
it {
|
30
|
-
expect
|
30
|
+
expect do
|
31
31
|
subject.diff(dsl)
|
32
|
-
|
32
|
+
end.to raise_error('Table `employees` already defined')
|
33
33
|
}
|
34
34
|
end
|
35
35
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when database is empty' do
|
3
3
|
let(:actual_dsl) { '' }
|
4
|
-
let(:expected_dsl)
|
5
|
-
erbh(<<-
|
4
|
+
let(:expected_dsl) do
|
5
|
+
erbh(<<-ERB)
|
6
6
|
create_table "clubs", force: :cascade do |t|
|
7
7
|
t.string "name", default: "", null: false
|
8
8
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -60,8 +60,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
60
60
|
t.date "to_date"
|
61
61
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
62
62
|
end
|
63
|
-
|
64
|
-
|
63
|
+
ERB
|
64
|
+
end
|
65
65
|
|
66
66
|
subject { client }
|
67
67
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when execute' do
|
3
|
-
let(:dsl)
|
4
|
-
erbh(<<-
|
3
|
+
let(:dsl) do
|
4
|
+
erbh(<<-ERB)
|
5
5
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
6
6
|
t.string "name", null: false
|
7
7
|
end
|
@@ -11,11 +11,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
11
11
|
t.integer "author_id", null: false
|
12
12
|
t.index ["author_id"], name: "idx_author_id", <%= i cond(5.0, using: :btree) %>
|
13
13
|
end
|
14
|
-
|
15
|
-
|
14
|
+
ERB
|
15
|
+
end
|
16
16
|
|
17
|
-
let(:dsl_with_execute)
|
18
|
-
erbh(<<-
|
17
|
+
let(:dsl_with_execute) do
|
18
|
+
erbh(<<-ERB)
|
19
19
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
20
20
|
t.string "name", null: false
|
21
21
|
end
|
@@ -29,8 +29,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
29
29
|
execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
|
30
30
|
c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= TEST_SCHEMA %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
|
31
31
|
end
|
32
|
-
|
33
|
-
|
32
|
+
ERB
|
33
|
+
end
|
34
34
|
|
35
35
|
before { subject.diff(dsl).migrate }
|
36
36
|
subject { client }
|
@@ -40,7 +40,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
40
40
|
expect(delta.differ?).to be_truthy
|
41
41
|
expect(subject.dump).to match_ruby dsl
|
42
42
|
|
43
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
43
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
44
44
|
CREATE TABLE `books` (
|
45
45
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
46
46
|
`title` varchar(255) NOT NULL,
|
@@ -48,15 +48,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
48
48
|
PRIMARY KEY (`id`),
|
49
49
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>
|
50
50
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
51
|
-
|
51
|
+
ERB
|
52
52
|
|
53
53
|
delta.migrate
|
54
54
|
|
55
|
-
expect(subject.dump).to match_fuzzy
|
55
|
+
expect(subject.dump).to match_fuzzy dsl + <<-RUBY
|
56
56
|
add_foreign_key "books", "authors", name: "fk_author"
|
57
|
-
|
57
|
+
RUBY
|
58
58
|
|
59
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
59
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
60
60
|
CREATE TABLE `books` (
|
61
61
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
62
62
|
`title` varchar(255) NOT NULL,
|
@@ -65,13 +65,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
65
65
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
|
66
66
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
67
67
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
68
|
-
|
68
|
+
ERB
|
69
69
|
}
|
70
70
|
end
|
71
71
|
|
72
72
|
context 'when not execute' do
|
73
|
-
let(:dsl)
|
74
|
-
erbh(<<-
|
73
|
+
let(:dsl) do
|
74
|
+
erbh(<<-ERB)
|
75
75
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
76
76
|
t.string "name", null: false
|
77
77
|
end
|
@@ -82,11 +82,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
82
82
|
t.index ["author_id"], name: "idx_author_id", <%= i cond(5.0, using: :btree) %>
|
83
83
|
end
|
84
84
|
add_foreign_key "books", "authors", name: "fk_author"
|
85
|
-
|
86
|
-
|
85
|
+
ERB
|
86
|
+
end
|
87
87
|
|
88
|
-
let(:dsl_with_execute)
|
89
|
-
erbh(<<-
|
88
|
+
let(:dsl_with_execute) do
|
89
|
+
erbh(<<-ERB)
|
90
90
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
91
91
|
t.string "name", null: false
|
92
92
|
end
|
@@ -102,8 +102,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
add_foreign_key "books", "authors", name: "fk_author"
|
105
|
-
|
106
|
-
|
105
|
+
ERB
|
106
|
+
end
|
107
107
|
|
108
108
|
before { subject.diff(dsl_with_execute).migrate }
|
109
109
|
subject { client }
|
@@ -113,7 +113,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
113
113
|
expect(delta.differ?).to be_truthy
|
114
114
|
expect(subject.dump).to match_ruby dsl
|
115
115
|
|
116
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
116
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
117
117
|
CREATE TABLE `books` (
|
118
118
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
119
119
|
`title` varchar(255) NOT NULL,
|
@@ -122,13 +122,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
122
122
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
|
123
123
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
124
124
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
125
|
-
|
125
|
+
ERB
|
126
126
|
|
127
|
-
migrated,
|
127
|
+
migrated, _out = delta.migrate
|
128
128
|
expect(migrated).to be_falsey
|
129
129
|
expect(subject.dump).to match_ruby dsl
|
130
130
|
|
131
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
131
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
132
132
|
CREATE TABLE `books` (
|
133
133
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
134
134
|
`title` varchar(255) NOT NULL,
|
@@ -137,13 +137,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
137
137
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
|
138
138
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
139
139
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
140
|
-
|
140
|
+
ERB
|
141
141
|
}
|
142
142
|
end
|
143
143
|
|
144
144
|
context 'when execute (noop)' do
|
145
|
-
let(:dsl)
|
146
|
-
erbh(<<-
|
145
|
+
let(:dsl) do
|
146
|
+
erbh(<<-ERB)
|
147
147
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
148
148
|
t.string "name", null: false
|
149
149
|
end
|
@@ -153,11 +153,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
153
153
|
t.integer "author_id", null: false
|
154
154
|
t.index ["author_id"], name: "idx_author_id", <%= i cond(5.0, using: :btree) %>
|
155
155
|
end
|
156
|
-
|
157
|
-
|
156
|
+
ERB
|
157
|
+
end
|
158
158
|
|
159
|
-
let(:dsl_with_execute)
|
160
|
-
erbh(<<-
|
159
|
+
let(:dsl_with_execute) do
|
160
|
+
erbh(<<-ERB)
|
161
161
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
162
162
|
t.string "name", null: false
|
163
163
|
end
|
@@ -171,8 +171,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
171
171
|
execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
|
172
172
|
c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= TEST_SCHEMA %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
|
173
173
|
end
|
174
|
-
|
175
|
-
|
174
|
+
ERB
|
175
|
+
end
|
176
176
|
|
177
177
|
before { subject.diff(dsl).migrate }
|
178
178
|
subject { client }
|
@@ -182,7 +182,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
182
182
|
expect(delta.differ?).to be_truthy
|
183
183
|
expect(subject.dump).to match_ruby dsl
|
184
184
|
|
185
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
185
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
186
186
|
CREATE TABLE `books` (
|
187
187
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
188
188
|
`title` varchar(255) NOT NULL,
|
@@ -190,15 +190,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
190
190
|
PRIMARY KEY (`id`),
|
191
191
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>
|
192
192
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
193
|
-
|
193
|
+
ERB
|
194
194
|
|
195
|
-
migrated, sql = delta.migrate(:
|
195
|
+
migrated, sql = delta.migrate(noop: true)
|
196
196
|
expect(migrated).to be_truthy
|
197
197
|
expect(subject.dump).to match_ruby dsl
|
198
198
|
|
199
|
-
expect(sql).to match_fuzzy
|
199
|
+
expect(sql).to match_fuzzy 'ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)'
|
200
200
|
|
201
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
201
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
202
202
|
CREATE TABLE `books` (
|
203
203
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
204
204
|
`title` varchar(255) NOT NULL,
|
@@ -206,13 +206,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
206
206
|
PRIMARY KEY (`id`),
|
207
207
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>
|
208
208
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
209
|
-
|
209
|
+
ERB
|
210
210
|
}
|
211
211
|
end
|
212
212
|
|
213
213
|
context 'when not execute (noop)' do
|
214
|
-
let(:dsl)
|
215
|
-
erbh(<<-
|
214
|
+
let(:dsl) do
|
215
|
+
erbh(<<-ERB)
|
216
216
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
217
217
|
t.string "name", null: false
|
218
218
|
end
|
@@ -223,11 +223,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
223
223
|
t.index ["author_id"], name: "idx_author_id", <%= i cond(5.0, using: :btree) %>
|
224
224
|
end
|
225
225
|
add_foreign_key "books", "authors", name: "fk_author"
|
226
|
-
|
227
|
-
|
226
|
+
ERB
|
227
|
+
end
|
228
228
|
|
229
|
-
let(:dsl_with_execute)
|
230
|
-
erbh(<<-
|
229
|
+
let(:dsl_with_execute) do
|
230
|
+
erbh(<<-ERB)
|
231
231
|
create_table "authors", <%= i cond('>= 5.1',id: :integer) + {force: :cascade} %> do |t|
|
232
232
|
t.string "name", null: false
|
233
233
|
end
|
@@ -243,8 +243,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
add_foreign_key "books", "authors", name: "fk_author"
|
246
|
-
|
247
|
-
|
246
|
+
ERB
|
247
|
+
end
|
248
248
|
|
249
249
|
before { subject.diff(dsl_with_execute).migrate }
|
250
250
|
subject { client }
|
@@ -254,7 +254,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
254
254
|
expect(delta.differ?).to be_truthy
|
255
255
|
expect(subject.dump).to match_ruby dsl
|
256
256
|
|
257
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
257
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
258
258
|
CREATE TABLE `books` (
|
259
259
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
260
260
|
`title` varchar(255) NOT NULL,
|
@@ -263,15 +263,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
263
263
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
|
264
264
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
265
265
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
266
|
-
|
266
|
+
ERB
|
267
267
|
|
268
|
-
migrated, sql = delta.migrate(:
|
268
|
+
migrated, sql = delta.migrate(noop: true)
|
269
269
|
expect(migrated).to be_falsey
|
270
270
|
expect(subject.dump).to match_ruby dsl
|
271
271
|
|
272
|
-
expect(sql).to match_fuzzy
|
272
|
+
expect(sql).to match_fuzzy ''
|
273
273
|
|
274
|
-
expect(show_create_table(:books)).to match_fuzzy erbh(<<-
|
274
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
|
275
275
|
CREATE TABLE `books` (
|
276
276
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
277
277
|
`title` varchar(255) NOT NULL,
|
@@ -280,7 +280,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
280
280
|
KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
|
281
281
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
282
282
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
283
|
-
|
283
|
+
ERB
|
284
284
|
}
|
285
285
|
end
|
286
286
|
end
|