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 create 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,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(:actual_dsl)
|
66
|
-
erbh(<<-
|
65
|
+
let(:actual_dsl) do
|
66
|
+
erbh(<<-ERB)
|
67
67
|
create_table "departments", primary_key: "dept_no", force: :cascade do |t|
|
68
68
|
t.string "dept_name", limit: 40, null: false
|
69
69
|
t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
@@ -102,15 +102,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
102
102
|
t.date "to_date"
|
103
103
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
104
104
|
end
|
105
|
-
|
106
|
-
|
105
|
+
ERB
|
106
|
+
end
|
107
107
|
|
108
108
|
let(:expected_dsl) { dsl }
|
109
109
|
|
110
110
|
before { client.diff(actual_dsl).migrate }
|
111
111
|
|
112
112
|
it {
|
113
|
-
tempfile("#{File.basename __FILE__}.#{
|
113
|
+
tempfile("#{File.basename __FILE__}.#{$PROCESS_ID}") do |path|
|
114
114
|
delta = client(log_file: path).diff(expected_dsl)
|
115
115
|
expect(delta.differ?).to be_truthy
|
116
116
|
expect(client.dump).to match_ruby actual_dsl
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when marge table' 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) %>
|
@@ -125,14 +125,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
125
125
|
t.date "to_date"
|
126
126
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
127
127
|
end
|
128
|
-
|
129
|
-
|
128
|
+
ERB
|
129
|
+
end
|
130
130
|
|
131
131
|
before { subject.diff(actual_dsl).migrate }
|
132
132
|
subject { client(merge: true) }
|
133
133
|
|
134
134
|
it {
|
135
|
-
delta = subject.diff(expected_dsl.gsub(/create_table "clubs".+\n\s*t\..+\n\s*end/,
|
135
|
+
delta = subject.diff(expected_dsl.gsub(/create_table "clubs".+\n\s*t\..+\n\s*end/, ''))
|
136
136
|
expect(delta.differ?).to be_truthy
|
137
137
|
expect(subject.dump).to match_ruby actual_dsl
|
138
138
|
delta.migrate
|
@@ -1,8 +1,8 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when no operation' do
|
3
3
|
let(:actual_dsl) { '' }
|
4
|
-
let(:expected_dsl)
|
5
|
-
<<-
|
4
|
+
let(:expected_dsl) do
|
5
|
+
<<-RUBY
|
6
6
|
create_table "clubs", force: :cascade do |t|
|
7
7
|
t.string "name", default: "", null: false
|
8
8
|
end
|
@@ -67,19 +67,19 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
70
|
-
|
71
|
-
|
70
|
+
RUBY
|
71
|
+
end
|
72
72
|
|
73
73
|
subject { client }
|
74
74
|
|
75
75
|
it {
|
76
76
|
delta = subject.diff(expected_dsl)
|
77
77
|
expect(delta.differ?).to be_truthy
|
78
|
-
migrated, sql = delta.migrate(:
|
78
|
+
migrated, sql = delta.migrate(noop: true)
|
79
79
|
expect(migrated).to be_truthy
|
80
80
|
expect(subject.dump).to match_ruby actual_dsl
|
81
81
|
|
82
|
-
expect(sql).to match_fuzzy erbh(<<-
|
82
|
+
expect(sql).to match_fuzzy erbh(<<-ERB)
|
83
83
|
CREATE TABLE `clubs` (`id` <%= cond('>= 5.1','bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
84
84
|
CREATE UNIQUE INDEX `idx_name` USING btree ON `clubs` (`name`)
|
85
85
|
CREATE TABLE `departments` (`dept_no` <%= cond('>= 5.1','bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `dept_name` varchar(40) NOT NULL) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
@@ -97,18 +97,18 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
97
97
|
CREATE INDEX `emp_no` USING btree ON `salaries` (`emp_no`)
|
98
98
|
CREATE TABLE `titles` (`emp_no` int NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
99
99
|
CREATE INDEX `emp_no` USING btree ON `titles` (`emp_no`)
|
100
|
-
|
100
|
+
ERB
|
101
101
|
}
|
102
102
|
|
103
103
|
it {
|
104
|
-
delta = client(:
|
104
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
105
105
|
expect(delta.differ?).to be_truthy
|
106
|
-
migrated, sql = delta.migrate(:
|
106
|
+
migrated, sql = delta.migrate(noop: true)
|
107
107
|
expect(migrated).to be_truthy
|
108
108
|
expect(subject.dump).to match_ruby actual_dsl
|
109
109
|
|
110
110
|
# XXX:
|
111
|
-
expect(sql.
|
111
|
+
expect(sql.delete('`')).to match_fuzzy erbh(<<-ERB).delete('`')
|
112
112
|
CREATE TABLE `clubs` (`id` <%= cond('>= 5.1','bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
113
113
|
ALTER TABLE `clubs` ADD UNIQUE INDEX `idx_name` USING btree (`name`)
|
114
114
|
CREATE TABLE `departments` (`dept_no` <%= cond('>= 5.1','bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `dept_name` varchar(40) NOT NULL) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
@@ -124,14 +124,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
124
124
|
ALTER TABLE `salaries` ADD INDEX `emp_no` USING btree (`emp_no`)
|
125
125
|
CREATE TABLE `titles` (`emp_no` int NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
126
126
|
ALTER TABLE `titles` ADD INDEX `emp_no` USING btree (`emp_no`)
|
127
|
-
|
127
|
+
ERB
|
128
128
|
}
|
129
129
|
end
|
130
130
|
|
131
131
|
context 'when no operation' do
|
132
132
|
let(:actual_dsl) { '' }
|
133
|
-
let(:expected_dsl)
|
134
|
-
<<-
|
133
|
+
let(:expected_dsl) do
|
134
|
+
<<-RUBY
|
135
135
|
create_table "clubs", force: :cascade do |t|
|
136
136
|
t.string "name", default: "", null: false
|
137
137
|
end
|
@@ -196,19 +196,19 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
196
196
|
end
|
197
197
|
|
198
198
|
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
199
|
-
|
200
|
-
|
199
|
+
RUBY
|
200
|
+
end
|
201
201
|
|
202
|
-
subject { client(:
|
202
|
+
subject { client(default_int_limit: 11) }
|
203
203
|
|
204
204
|
it {
|
205
205
|
delta = subject.diff(expected_dsl)
|
206
206
|
expect(delta.differ?).to be_truthy
|
207
|
-
migrated, sql = delta.migrate(:
|
207
|
+
migrated, sql = delta.migrate(noop: true)
|
208
208
|
expect(migrated).to be_truthy
|
209
209
|
expect(subject.dump).to match_ruby actual_dsl
|
210
210
|
|
211
|
-
expect(sql).to match_fuzzy erbh(<<-
|
211
|
+
expect(sql).to match_fuzzy erbh(<<-ERB)
|
212
212
|
CREATE TABLE `clubs` (`id` <%= cond('>= 5.1','bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
213
213
|
CREATE UNIQUE INDEX `idx_name` USING btree ON `clubs` (`name`)
|
214
214
|
CREATE TABLE `departments` (`dept_no` <%= cond('>= 5.1','bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `dept_name` varchar(40) NOT NULL) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
@@ -226,7 +226,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
226
226
|
CREATE INDEX `emp_no` USING btree ON `salaries` (`emp_no`)
|
227
227
|
CREATE TABLE `titles` (`emp_no` int NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) <%= cond('< 5.2.0.beta2', 'ENGINE=InnoDB') %>
|
228
228
|
CREATE INDEX `emp_no` USING btree ON `titles` (`emp_no`)
|
229
|
-
|
229
|
+
ERB
|
230
230
|
}
|
231
231
|
end
|
232
232
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
-
let(:actual_dsl)
|
3
|
-
erbh(<<-
|
2
|
+
let(:actual_dsl) do
|
3
|
+
erbh(<<-ERB)
|
4
4
|
create_table "employees", id: :integer, unsigned: true, force: :cascade do |t|
|
5
5
|
end
|
6
|
-
|
7
|
-
|
6
|
+
ERB
|
7
|
+
end
|
8
8
|
|
9
9
|
before { subject.diff(actual_dsl).migrate }
|
10
10
|
subject { client(allow_pk_change: allow_pk_change) }
|
@@ -13,19 +13,19 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
13
13
|
let(:allow_pk_change) { false }
|
14
14
|
|
15
15
|
context 'with difference' do
|
16
|
-
let(:expected_dsl)
|
17
|
-
erbh(<<-
|
16
|
+
let(:expected_dsl) do
|
17
|
+
erbh(<<-ERB)
|
18
18
|
create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
|
19
19
|
end
|
20
|
-
|
21
|
-
|
20
|
+
ERB
|
21
|
+
end
|
22
22
|
|
23
23
|
it {
|
24
|
-
expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-
|
24
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-MSG)
|
25
25
|
[WARNING] Primary key definition of `employees` differ but `allow_pk_change` option is false
|
26
26
|
from: {:id=>:integer, :unsigned=>true}
|
27
27
|
to: {:id=>:bigint, :unsigned=>true}
|
28
|
-
|
28
|
+
MSG
|
29
29
|
|
30
30
|
delta = subject.diff(expected_dsl)
|
31
31
|
expect(delta.differ?).to be_falsey
|
@@ -35,12 +35,12 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with no difference' do
|
38
|
-
let(:actual_dsl)
|
39
|
-
erbh(<<-
|
38
|
+
let(:actual_dsl) do
|
39
|
+
erbh(<<-ERB)
|
40
40
|
create_table "employees", unsigned: true, force: :cascade do |t|
|
41
41
|
end
|
42
|
-
|
43
|
-
|
42
|
+
ERB
|
43
|
+
end
|
44
44
|
let(:expected_dsl) { actual_dsl }
|
45
45
|
|
46
46
|
it {
|
@@ -54,8 +54,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
54
54
|
|
55
55
|
context 'when allow_pk_change option is true' do
|
56
56
|
let(:allow_pk_change) { true }
|
57
|
-
let(:expected_dsl)
|
58
|
-
erbh(<<-
|
57
|
+
let(:expected_dsl) do
|
58
|
+
erbh(<<-ERB)
|
59
59
|
create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
|
60
60
|
end
|
61
61
|
|
@@ -64,8 +64,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
64
64
|
t.index ["employee_id"], name: "fk_salaries_employees", <%= i cond(5.0, using: :btree) %>
|
65
65
|
end
|
66
66
|
add_foreign_key "salaries", "employees", name: "fk_salaries_employees"
|
67
|
-
|
68
|
-
|
67
|
+
ERB
|
68
|
+
end
|
69
69
|
|
70
70
|
it {
|
71
71
|
delta = subject.diff(expected_dsl)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when rename 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) %>
|
@@ -121,8 +121,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
121
121
|
t.date "to_date"
|
122
122
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
123
123
|
end
|
124
|
-
|
125
|
-
|
124
|
+
ERB
|
125
|
+
end
|
126
126
|
|
127
127
|
before { subject.diff(actual_dsl).migrate }
|
128
128
|
subject { client }
|
@@ -136,10 +136,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
136
136
|
}
|
137
137
|
|
138
138
|
it {
|
139
|
-
delta = client(:
|
139
|
+
delta = client(bulk_change: true).diff(expected_dsl)
|
140
140
|
expect(delta.differ?).to be_truthy
|
141
141
|
expect(subject.dump).to match_ruby actual_dsl
|
142
|
-
expect(delta.script).to match_fuzzy <<-
|
142
|
+
expect(delta.script).to match_fuzzy <<-RUBY
|
143
143
|
change_table("dept_emp", {:bulk => true}) do |t|
|
144
144
|
t.rename("from_date", "from_date2")
|
145
145
|
end
|
@@ -151,7 +151,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
151
151
|
change_table("employees", {:bulk => true}) do |t|
|
152
152
|
t.rename("gender", "gender2")
|
153
153
|
end
|
154
|
-
|
154
|
+
RUBY
|
155
155
|
delta.migrate
|
156
156
|
expect(subject.dump).to match_ruby expected_dsl.gsub(/\s*,\s*renamed_from:.*$/, '')
|
157
157
|
}
|
@@ -161,8 +161,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
161
161
|
before { restore_tables }
|
162
162
|
subject { client }
|
163
163
|
|
164
|
-
let(:dsl)
|
165
|
-
<<-
|
164
|
+
let(:dsl) do
|
165
|
+
<<-RUBY
|
166
166
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
167
167
|
t.date "birth_date", null: false
|
168
168
|
t.string "first_name", limit: 14, null: false
|
@@ -170,13 +170,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
170
170
|
t.string "gender2", limit: 1, null: false, renamed_from: 'age'
|
171
171
|
t.date "hire_date", null: false
|
172
172
|
end
|
173
|
-
|
174
|
-
|
173
|
+
RUBY
|
174
|
+
end
|
175
175
|
|
176
176
|
it {
|
177
|
-
expect
|
177
|
+
expect do
|
178
178
|
subject.diff(dsl)
|
179
|
-
|
179
|
+
end.to raise_error('Column `age` not found')
|
180
180
|
}
|
181
181
|
end
|
182
182
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
2
|
context 'when rename table' 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) %>
|
@@ -121,8 +121,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
121
121
|
t.date "to_date"
|
122
122
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
123
123
|
end
|
124
|
-
|
125
|
-
|
124
|
+
ERB
|
125
|
+
end
|
126
126
|
|
127
127
|
before { subject.diff(actual_dsl).migrate }
|
128
128
|
subject { client }
|
@@ -137,8 +137,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
137
137
|
end
|
138
138
|
|
139
139
|
context 'when rename table (dry-run)' do
|
140
|
-
let(:actual_dsl)
|
141
|
-
erbh(<<-
|
140
|
+
let(:actual_dsl) do
|
141
|
+
erbh(<<-ERB)
|
142
142
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
143
143
|
t.date "birth_date", null: false
|
144
144
|
t.string "first_name", limit: 14, null: false
|
@@ -156,11 +156,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
156
156
|
t.date "hire_date", null: false
|
157
157
|
t.index ["first_name"], name: "first_name", <%= i cond(5.0, using: :btree) %>
|
158
158
|
end
|
159
|
-
|
160
|
-
|
159
|
+
ERB
|
160
|
+
end
|
161
161
|
|
162
|
-
let(:expected_dsl)
|
163
|
-
erbh(<<-
|
162
|
+
let(:expected_dsl) do
|
163
|
+
erbh(<<-ERB)
|
164
164
|
create_table "employees2", primary_key: "emp_no", force: :cascade, renamed_from: 'employees' do |t|
|
165
165
|
t.date "birth_date", null: false
|
166
166
|
t.string "first_name", limit: 14, null: false
|
@@ -178,8 +178,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
178
178
|
t.date "hire_date", null: false
|
179
179
|
t.index ["first_name"], name: "first_name", <%= i cond(5.0, using: :btree) %>
|
180
180
|
end
|
181
|
-
|
182
|
-
|
181
|
+
ERB
|
182
|
+
end
|
183
183
|
|
184
184
|
before { subject.diff(actual_dsl).migrate }
|
185
185
|
subject { client }
|
@@ -197,8 +197,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
197
197
|
before { restore_tables }
|
198
198
|
subject { client }
|
199
199
|
|
200
|
-
let(:dsl)
|
201
|
-
erbh(<<-
|
200
|
+
let(:dsl) do
|
201
|
+
erbh(<<-ERB)
|
202
202
|
create_table "employees2", primary_key: "emp_no", force: :cascade, renamed_from: 'not_employees' do |t|
|
203
203
|
t.date "birth_date", null: false
|
204
204
|
t.string "first_name", limit: 14, null: false
|
@@ -206,11 +206,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
206
206
|
t.string "gender", limit: 1, null: false
|
207
207
|
t.date "hire_date", null: false
|
208
208
|
end
|
209
|
-
|
210
|
-
|
209
|
+
ERB
|
210
|
+
end
|
211
211
|
|
212
212
|
it {
|
213
|
-
expect(Ridgepole::Logger.instance).to receive(:warn).with(
|
213
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with('[WARNING] The table `not_employees` to be renamed does not exist.')
|
214
214
|
subject.diff(dsl)
|
215
215
|
}
|
216
216
|
end
|
@@ -219,8 +219,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
219
219
|
before { subject.diff(dsl).migrate }
|
220
220
|
subject { client }
|
221
221
|
|
222
|
-
let(:dsl)
|
223
|
-
erbh(<<-
|
222
|
+
let(:dsl) do
|
223
|
+
erbh(<<-ERB)
|
224
224
|
create_table "employees2", primary_key: "emp_no", force: :cascade, renamed_from: 'employees' do |t|
|
225
225
|
t.date "birth_date", null: false
|
226
226
|
t.string "first_name", limit: 14, null: false
|
@@ -228,11 +228,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
228
228
|
t.string "gender", limit: 1, null: false
|
229
229
|
t.date "hire_date", null: false
|
230
230
|
end
|
231
|
-
|
232
|
-
|
231
|
+
ERB
|
232
|
+
end
|
233
233
|
|
234
234
|
it {
|
235
|
-
expect(Ridgepole::Logger.instance).to receive(:warn).with(
|
235
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with('[WARNING] The table `employees` has already been renamed to the table `employees2`.')
|
236
236
|
subject.diff(dsl)
|
237
237
|
}
|
238
238
|
end
|