ridgepole 0.9.2 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/lib/ridgepole/delta.rb +1 -1
  4. data/lib/ridgepole/diff.rb +7 -3
  5. data/lib/ridgepole/execute_expander.rb +1 -1
  6. data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +1 -0
  7. data/lib/ridgepole/version.rb +1 -1
  8. data/ridgepole.gemspec +7 -4
  9. metadata +6 -282
  10. data/.github/workflows/test.yml +0 -70
  11. data/.gitignore +0 -25
  12. data/spec/cli_helper.rb +0 -65
  13. data/spec/dsl_parser/context_spec.rb +0 -16
  14. data/spec/erb_helper.rb +0 -26
  15. data/spec/fixtures/for_require_relative_spec.rb +0 -3
  16. data/spec/hide_pending_formatter.rb +0 -9
  17. data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +0 -40
  18. data/spec/mysql/bigint_pk/int_pk_spec.rb +0 -47
  19. data/spec/mysql/cli/config_spec.rb +0 -210
  20. data/spec/mysql/cli/ridgepole_spec.rb +0 -447
  21. data/spec/mysql/collation/collation_spec.rb +0 -153
  22. data/spec/mysql/comment/comment_spec.rb +0 -179
  23. data/spec/mysql/default_lambda/default_lambda_spec.rb +0 -164
  24. data/spec/mysql/diff/diff2_spec.rb +0 -189
  25. data/spec/mysql/diff/diff_spec.rb +0 -168
  26. data/spec/mysql/dump/dump_class_method_spec.rb +0 -74
  27. data/spec/mysql/dump/dump_some_tables_spec.rb +0 -70
  28. data/spec/mysql/dump/dump_spec.rb +0 -74
  29. data/spec/mysql/dump/dump_unknown_column_type_spec.rb +0 -28
  30. data/spec/mysql/dump/dump_without_table_options_spec.rb +0 -34
  31. data/spec/mysql/fk/migrate_change_fk2_spec.rb +0 -47
  32. data/spec/mysql/fk/migrate_change_fk_spec.rb +0 -265
  33. data/spec/mysql/fk/migrate_create_fk_spec.rb +0 -349
  34. data/spec/mysql/fk/migrate_drop_fk_spec.rb +0 -331
  35. data/spec/mysql/fk/migrate_fk_with_column_spec.rb +0 -163
  36. data/spec/mysql/fk/migrate_ignore_fk_spec.rb +0 -70
  37. data/spec/mysql/migrate/check_orphan_index_spec.rb +0 -83
  38. data/spec/mysql/migrate/migrate_add_column2_spec.rb +0 -159
  39. data/spec/mysql/migrate/migrate_add_column_order_spec.rb +0 -242
  40. data/spec/mysql/migrate/migrate_add_column_spec.rb +0 -161
  41. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +0 -231
  42. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +0 -152
  43. data/spec/mysql/migrate/migrate_change_column2_spec.rb +0 -91
  44. data/spec/mysql/migrate/migrate_change_column3_spec.rb +0 -404
  45. data/spec/mysql/migrate/migrate_change_column4_spec.rb +0 -83
  46. data/spec/mysql/migrate/migrate_change_column5_spec.rb +0 -129
  47. data/spec/mysql/migrate/migrate_change_column6_spec.rb +0 -241
  48. data/spec/mysql/migrate/migrate_change_column7_spec.rb +0 -25
  49. data/spec/mysql/migrate/migrate_change_column8_spec.rb +0 -87
  50. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +0 -199
  51. data/spec/mysql/migrate/migrate_change_column_float_spec.rb +0 -75
  52. data/spec/mysql/migrate/migrate_change_column_spec.rb +0 -158
  53. data/spec/mysql/migrate/migrate_change_index2_spec.rb +0 -86
  54. data/spec/mysql/migrate/migrate_change_index3_spec.rb +0 -179
  55. data/spec/mysql/migrate/migrate_change_index4_spec.rb +0 -112
  56. data/spec/mysql/migrate/migrate_change_index5_spec.rb +0 -74
  57. data/spec/mysql/migrate/migrate_change_index6_spec.rb +0 -202
  58. data/spec/mysql/migrate/migrate_change_index7_spec.rb +0 -85
  59. data/spec/mysql/migrate/migrate_change_index8_spec.rb +0 -85
  60. data/spec/mysql/migrate/migrate_change_index_spec.rb +0 -235
  61. data/spec/mysql/migrate/migrate_change_table_comment_spec.rb +0 -72
  62. data/spec/mysql/migrate/migrate_change_table_option_spec.rb +0 -83
  63. data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +0 -225
  64. data/spec/mysql/migrate/migrate_create_index2_spec.rb +0 -203
  65. data/spec/mysql/migrate/migrate_create_index_spec.rb +0 -220
  66. data/spec/mysql/migrate/migrate_create_table_spec.rb +0 -123
  67. data/spec/mysql/migrate/migrate_create_table_with_ignore_spec.rb +0 -45
  68. data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +0 -43
  69. data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +0 -59
  70. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +0 -132
  71. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +0 -140
  72. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +0 -167
  73. data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +0 -52
  74. data/spec/mysql/migrate/migrate_drop_column_spec.rb +0 -158
  75. data/spec/mysql/migrate/migrate_drop_index_spec.rb +0 -160
  76. data/spec/mysql/migrate/migrate_drop_table_spec.rb +0 -123
  77. data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +0 -27
  78. data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +0 -37
  79. data/spec/mysql/migrate/migrate_empty_spec.rb +0 -78
  80. data/spec/mysql/migrate/migrate_execute_spec.rb +0 -288
  81. data/spec/mysql/migrate/migrate_ignore_column_spec.rb +0 -98
  82. data/spec/mysql/migrate/migrate_ignore_index_spec.rb +0 -92
  83. data/spec/mysql/migrate/migrate_log_file_spec.rb +0 -125
  84. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +0 -145
  85. data/spec/mysql/migrate/migrate_noop_spec.rb +0 -234
  86. data/spec/mysql/migrate/migrate_primary_key_spec.rb +0 -104
  87. data/spec/mysql/migrate/migrate_rename_column_spec.rb +0 -184
  88. data/spec/mysql/migrate/migrate_rename_table_spec.rb +0 -241
  89. data/spec/mysql/migrate/migrate_same_default_null_spec.rb +0 -77
  90. data/spec/mysql/migrate/migrate_same_spec.rb +0 -82
  91. data/spec/mysql/migrate/migrate_script_error_spec.rb +0 -91
  92. data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +0 -39
  93. data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +0 -145
  94. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +0 -140
  95. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +0 -141
  96. data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +0 -307
  97. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +0 -153
  98. data/spec/mysql/migrate/migrate_with_tables_spec.rb +0 -149
  99. data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +0 -60
  100. data/spec/mysql/ridgepole_test_database.sql +0 -2
  101. data/spec/mysql/ridgepole_test_tables.sql +0 -79
  102. data/spec/mysql/ridgepole_test_tables_unknown_column_type.sql +0 -17
  103. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +0 -131
  104. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +0 -59
  105. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +0 -133
  106. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +0 -100
  107. data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +0 -43
  108. data/spec/mysql57/json/add_json_column_spec.rb +0 -35
  109. data/spec/mysql57/json/change_json_column_spec.rb +0 -102
  110. data/spec/mysql57/json/drop_json_column_spec.rb +0 -35
  111. data/spec/mysql57/virtual/add_virtual_column_spec.rb +0 -37
  112. data/spec/mysql57/virtual/change_virtual_column_spec.rb +0 -40
  113. data/spec/mysql57/virtual/drop_virtual_column_spec.rb +0 -37
  114. data/spec/postgresql/diff/diff_spec.rb +0 -216
  115. data/spec/postgresql/dump/dump_spec.rb +0 -69
  116. data/spec/postgresql/fk/migrate_change_fk_spec.rb +0 -115
  117. data/spec/postgresql/fk/migrate_create_fk_spec.rb +0 -176
  118. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +0 -197
  119. data/spec/postgresql/migrate/migrate_add_column_spec.rb +0 -203
  120. data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +0 -25
  121. data/spec/postgresql/migrate/migrate_bigint_spec.rb +0 -53
  122. data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +0 -38
  123. data/spec/postgresql/migrate/migrate_change_column_spec.rb +0 -185
  124. data/spec/postgresql/migrate/migrate_change_index_spec.rb +0 -164
  125. data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +0 -114
  126. data/spec/postgresql/migrate/migrate_create_table_spec.rb +0 -120
  127. data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +0 -112
  128. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +0 -163
  129. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +0 -166
  130. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +0 -59
  131. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +0 -158
  132. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +0 -122
  133. data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +0 -64
  134. data/spec/postgresql/migrate/migrate_primary_key2_spec.rb +0 -73
  135. data/spec/postgresql/migrate/migrate_primary_key_spec.rb +0 -99
  136. data/spec/postgresql/migrate/migrate_references_spec.rb +0 -90
  137. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +0 -155
  138. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +0 -175
  139. data/spec/postgresql/migrate/migrate_same_spec.rb +0 -77
  140. data/spec/postgresql/ridgepole_test_database.sql +0 -16
  141. data/spec/postgresql/ridgepole_test_tables.sql +0 -75
  142. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +0 -59
  143. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +0 -134
  144. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +0 -100
  145. data/spec/processing_for_ci.rb +0 -13
  146. data/spec/spec_condition.rb +0 -58
  147. data/spec/spec_const.rb +0 -20
  148. data/spec/spec_helper.rb +0 -173
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when table already defined' do
5
- let(:dsl) do
6
- <<-RUBY
7
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
8
- t.date "birth_date", null: false
9
- t.string "first_name", limit: 14, null: false
10
- t.string "last_name", limit: 16, null: false
11
- t.string "gender", limit: 1, null: false
12
- t.date "hire_date", null: false
13
- t.integer "age", unsigned: true, null: false
14
- t.date "updated_at"
15
- end
16
-
17
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
18
- t.date "birth_date", null: false
19
- t.string "first_name", limit: 14, null: false
20
- t.string "last_name", limit: 16, null: false
21
- t.string "gender", limit: 1, null: false
22
- t.date "hire_date", null: false
23
- t.integer "age", unsigned: true, null: false
24
- t.date "updated_at"
25
- end
26
- RUBY
27
- end
28
-
29
- subject { client }
30
-
31
- it {
32
- expect do
33
- subject.diff(dsl)
34
- end.to raise_error('Table `employees` already defined')
35
- }
36
- end
37
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when database is empty' do
5
- let(:actual_dsl) { '' }
6
- let(:expected_dsl) do
7
- erbh(<<-ERB)
8
- create_table "clubs", force: :cascade do |t|
9
- t.string "name", default: "", null: false
10
- t.index ["name"], name: "idx_name", unique: true
11
- end
12
-
13
- create_table "departments", primary_key: "dept_no", force: :cascade do |t|
14
- t.string "dept_name", limit: 40, null: false
15
- t.index ["dept_name"], name: "dept_name", unique: true
16
- end
17
-
18
- create_table "dept_emp", id: false, force: :cascade do |t|
19
- t.integer "emp_no", null: false
20
- t.string "dept_no", null: false
21
- t.date "from_date", null: false
22
- t.date "to_date", null: false
23
- t.index ["dept_no"], name: "dept_no"
24
- t.index ["emp_no"], name: "emp_no"
25
- end
26
-
27
- create_table "dept_manager", id: false, force: :cascade do |t|
28
- t.string "dept_no", null: false
29
- t.integer "emp_no", null: false
30
- t.date "from_date", null: false
31
- t.date "to_date", null: false
32
- t.index ["dept_no"], name: "dept_no"
33
- t.index ["emp_no"], name: "emp_no"
34
- end
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
- t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
40
- end
41
-
42
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
43
- t.date "birth_date", null: false
44
- t.string "first_name", limit: 14, null: false
45
- t.string "last_name", limit: 16, null: false
46
- t.string "gender", limit: 1, 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
- t.index ["emp_no"], name: "emp_no"
56
- end
57
-
58
- create_table "titles", id: false, force: :cascade do |t|
59
- t.integer "emp_no", null: false
60
- t.string "title", limit: 50, null: false
61
- t.date "from_date", null: false
62
- t.date "to_date"
63
- t.index ["emp_no"], name: "emp_no"
64
- end
65
- ERB
66
- end
67
-
68
- subject { client }
69
-
70
- it {
71
- delta = subject.diff(expected_dsl)
72
- expect(delta.differ?).to be_truthy
73
- expect(subject.dump).to match_ruby actual_dsl
74
- delta.migrate
75
- expect(subject.dump).to match_ruby expected_dsl
76
- }
77
- end
78
- end
@@ -1,288 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when execute' do
5
- let(:dsl) do
6
- erbh(<<-ERB)
7
- create_table "authors", id: :integer, force: :cascade do |t|
8
- t.string "name", null: false
9
- end
10
-
11
- create_table "books", id: :integer, force: :cascade do |t|
12
- t.string "title", null: false
13
- t.integer "author_id", null: false
14
- t.index ["author_id"], name: "idx_author_id"
15
- end
16
- ERB
17
- end
18
-
19
- let(:dsl_with_execute) do
20
- erbh(<<-ERB)
21
- create_table "authors", id: :integer, force: :cascade do |t|
22
- t.string "name", null: false
23
- end
24
-
25
- create_table "books", id: :integer, force: :cascade do |t|
26
- t.string "title", null: false
27
- t.integer "author_id", null: false
28
- t.index ["author_id"], name: "idx_author_id"
29
- end
30
-
31
- execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
32
- 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?
33
- end
34
- ERB
35
- end
36
-
37
- before { subject.diff(dsl).migrate }
38
- subject { client }
39
-
40
- it {
41
- delta = subject.diff(dsl_with_execute)
42
- expect(delta.differ?).to be_truthy
43
- expect(subject.dump).to match_ruby dsl
44
-
45
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
46
- CREATE TABLE `books` (
47
- `id` int(11) NOT NULL AUTO_INCREMENT,
48
- `title` varchar(255) NOT NULL,
49
- `author_id` int(11) NOT NULL,
50
- PRIMARY KEY (`id`),
51
- KEY `idx_author_id` (`author_id`)
52
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
53
- ERB
54
-
55
- delta.migrate
56
-
57
- expect(subject.dump).to match_fuzzy dsl + <<-RUBY
58
- add_foreign_key "books", "authors", name: "fk_author"
59
- RUBY
60
-
61
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
62
- CREATE TABLE `books` (
63
- `id` int(11) NOT NULL AUTO_INCREMENT,
64
- `title` varchar(255) NOT NULL,
65
- `author_id` int(11) NOT NULL,
66
- PRIMARY KEY (`id`),
67
- KEY `idx_author_id` (`author_id`),
68
- CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
69
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
70
- ERB
71
- }
72
- end
73
-
74
- context 'when not execute' do
75
- let(:dsl) do
76
- erbh(<<-ERB)
77
- create_table "authors", id: :integer, force: :cascade do |t|
78
- t.string "name", null: false
79
- end
80
-
81
- create_table "books", id: :integer, force: :cascade do |t|
82
- t.string "title", null: false
83
- t.integer "author_id", null: false
84
- t.index ["author_id"], name: "idx_author_id"
85
- end
86
- add_foreign_key "books", "authors", name: "fk_author"
87
- ERB
88
- end
89
-
90
- let(:dsl_with_execute) do
91
- erbh(<<-ERB)
92
- create_table "authors", id: :integer, force: :cascade do |t|
93
- t.string "name", null: false
94
- end
95
-
96
- create_table "books", id: :integer, force: :cascade do |t|
97
- t.string "title", null: false
98
- t.integer "author_id", null: false
99
- t.index ["author_id"], name: "idx_author_id"
100
- end
101
-
102
- execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
103
- 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?
104
- end
105
-
106
- add_foreign_key "books", "authors", name: "fk_author"
107
- ERB
108
- end
109
-
110
- before { subject.diff(dsl_with_execute).migrate }
111
- subject { client }
112
-
113
- it {
114
- delta = subject.diff(dsl_with_execute)
115
- expect(delta.differ?).to be_truthy
116
- expect(subject.dump).to match_ruby dsl
117
-
118
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
119
- CREATE TABLE `books` (
120
- `id` int(11) NOT NULL AUTO_INCREMENT,
121
- `title` varchar(255) NOT NULL,
122
- `author_id` int(11) NOT NULL,
123
- PRIMARY KEY (`id`),
124
- KEY `idx_author_id` (`author_id`),
125
- CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
126
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
127
- ERB
128
-
129
- migrated, _out = delta.migrate
130
- expect(migrated).to be_falsey
131
- expect(subject.dump).to match_ruby dsl
132
-
133
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
134
- CREATE TABLE `books` (
135
- `id` int(11) NOT NULL AUTO_INCREMENT,
136
- `title` varchar(255) NOT NULL,
137
- `author_id` int(11) NOT NULL,
138
- PRIMARY KEY (`id`),
139
- KEY `idx_author_id` (`author_id`),
140
- CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
141
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
142
- ERB
143
- }
144
- end
145
-
146
- context 'when execute (noop)' do
147
- let(:dsl) do
148
- erbh(<<-ERB)
149
- create_table "authors", id: :integer, force: :cascade do |t|
150
- t.string "name", null: false
151
- end
152
-
153
- create_table "books", id: :integer, force: :cascade do |t|
154
- t.string "title", null: false
155
- t.integer "author_id", null: false
156
- t.index ["author_id"], name: "idx_author_id"
157
- end
158
- ERB
159
- end
160
-
161
- let(:dsl_with_execute) do
162
- erbh(<<-ERB)
163
- create_table "authors", id: :integer, force: :cascade do |t|
164
- t.string "name", null: false
165
- end
166
-
167
- create_table "books", id: :integer, force: :cascade do |t|
168
- t.string "title", null: false
169
- t.integer "author_id", null: false
170
- t.index ["author_id"], name: "idx_author_id"
171
- end
172
-
173
- execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
174
- 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?
175
- end
176
- ERB
177
- end
178
-
179
- before { subject.diff(dsl).migrate }
180
- subject { client }
181
-
182
- it {
183
- delta = subject.diff(dsl_with_execute)
184
- expect(delta.differ?).to be_truthy
185
- expect(subject.dump).to match_ruby dsl
186
-
187
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
188
- CREATE TABLE `books` (
189
- `id` int(11) NOT NULL AUTO_INCREMENT,
190
- `title` varchar(255) NOT NULL,
191
- `author_id` int(11) NOT NULL,
192
- PRIMARY KEY (`id`),
193
- KEY `idx_author_id` (`author_id`)
194
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
195
- ERB
196
-
197
- migrated, sql = delta.migrate(noop: true)
198
- expect(migrated).to be_truthy
199
- expect(subject.dump).to match_ruby dsl
200
-
201
- expect(sql).to match_fuzzy 'ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)'
202
-
203
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
204
- CREATE TABLE `books` (
205
- `id` int(11) NOT NULL AUTO_INCREMENT,
206
- `title` varchar(255) NOT NULL,
207
- `author_id` int(11) NOT NULL,
208
- PRIMARY KEY (`id`),
209
- KEY `idx_author_id` (`author_id`)
210
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
211
- ERB
212
- }
213
- end
214
-
215
- context 'when not execute (noop)' do
216
- let(:dsl) do
217
- erbh(<<-ERB)
218
- create_table "authors", id: :integer, force: :cascade do |t|
219
- t.string "name", null: false
220
- end
221
-
222
- create_table "books", id: :integer, force: :cascade do |t|
223
- t.string "title", null: false
224
- t.integer "author_id", null: false
225
- t.index ["author_id"], name: "idx_author_id"
226
- end
227
- add_foreign_key "books", "authors", name: "fk_author"
228
- ERB
229
- end
230
-
231
- let(:dsl_with_execute) do
232
- erbh(<<-ERB)
233
- create_table "authors", id: :integer, force: :cascade do |t|
234
- t.string "name", null: false
235
- end
236
-
237
- create_table "books", id: :integer, force: :cascade do |t|
238
- t.string "title", null: false
239
- t.integer "author_id", null: false
240
- t.index ["author_id"], name: "idx_author_id"
241
- end
242
-
243
- execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
244
- 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?
245
- end
246
-
247
- add_foreign_key "books", "authors", name: "fk_author"
248
- ERB
249
- end
250
-
251
- before { subject.diff(dsl_with_execute).migrate }
252
- subject { client }
253
-
254
- it {
255
- delta = subject.diff(dsl_with_execute)
256
- expect(delta.differ?).to be_truthy
257
- expect(subject.dump).to match_ruby dsl
258
-
259
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
260
- CREATE TABLE `books` (
261
- `id` int(11) NOT NULL AUTO_INCREMENT,
262
- `title` varchar(255) NOT NULL,
263
- `author_id` int(11) NOT NULL,
264
- PRIMARY KEY (`id`),
265
- KEY `idx_author_id` (`author_id`),
266
- CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
267
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
268
- ERB
269
-
270
- migrated, sql = delta.migrate(noop: true)
271
- expect(migrated).to be_falsey
272
- expect(subject.dump).to match_ruby dsl
273
-
274
- expect(sql).to match_fuzzy ''
275
-
276
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-ERB)
277
- CREATE TABLE `books` (
278
- `id` int(11) NOT NULL AUTO_INCREMENT,
279
- `title` varchar(255) NOT NULL,
280
- `author_id` int(11) NOT NULL,
281
- PRIMARY KEY (`id`),
282
- KEY `idx_author_id` (`author_id`),
283
- CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
284
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
285
- ERB
286
- }
287
- end
288
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when add column with ignore:true' do
5
- let(:actual_dsl) do
6
- erbh(<<-ERB)
7
- create_table "employee_clubs", force: :cascade do |t|
8
- t.integer "emp_no", null: false
9
- t.integer "club_id", null: false
10
- t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
11
- end
12
-
13
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
14
- t.date "birth_date", null: false
15
- t.string "first_name", limit: 14, null: false
16
- t.string "last_name", limit: 16, null: false
17
- t.string "gender", limit: 1, null: false
18
- t.date "hire_date", null: false
19
- end
20
- ERB
21
- end
22
-
23
- let(:expected_dsl) do
24
- erbh(<<-ERB)
25
- create_table "employee_clubs", force: :cascade do |t|
26
- t.integer "emp_no", null: false
27
- t.integer "club_id", null: false
28
- t.string "any_col", null: false, ignore: true
29
- t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
30
- end
31
-
32
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
33
- t.date "birth_date", null: false
34
- t.string "first_name", limit: 14, null: false
35
- t.string "last_name", limit: 16, null: false
36
- t.string "gender", limit: 1, null: false
37
- t.date "hire_date", null: false
38
- t.integer "age", null: false, ignore: true
39
- t.date "updated_at", ignore: true
40
- end
41
- ERB
42
- end
43
-
44
- before { subject.diff(actual_dsl).migrate }
45
- subject { client }
46
-
47
- it {
48
- delta = subject.diff(expected_dsl)
49
- expect(delta.differ?).to be_falsey
50
- }
51
- end
52
-
53
- context 'when change column with ignore:true' do
54
- let(:actual_dsl) do
55
- erbh(<<-ERB)
56
- create_table "employee_clubs", force: :cascade do |t|
57
- t.integer "emp_no", null: false
58
- t.integer "club_id", null: false
59
- t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
60
- end
61
-
62
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
63
- t.date "birth_date", null: false
64
- t.string "first_name", limit: 14, null: false
65
- t.string "last_name", limit: 16, null: false
66
- t.string "gender", limit: 1, null: false
67
- t.date "hire_date", null: false
68
- end
69
- ERB
70
- end
71
-
72
- let(:expected_dsl) do
73
- erbh(<<-ERB)
74
- create_table "employee_clubs", force: :cascade do |t|
75
- t.integer "emp_no", null: false
76
- t.integer "club_id", ignore: true
77
- t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
78
- end
79
-
80
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
81
- t.date "birth_date", null: false
82
- t.string "first_name", limit: 14, null: false
83
- t.string "last_name", limit: 20, default: "XXX", null: false, ignore: true
84
- t.string "gender", limit: 2, null: false, ignore: true
85
- t.date "hire_date", null: false
86
- end
87
- ERB
88
- end
89
-
90
- before { subject.diff(actual_dsl).migrate }
91
- subject { client }
92
-
93
- it {
94
- delta = subject.diff(expected_dsl)
95
- expect(delta.differ?).to be_falsey
96
- }
97
- end
98
- end