ridgepole 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/lib/ridgepole/delta.rb +1 -1
  4. data/lib/ridgepole/version.rb +1 -1
  5. data/ridgepole.gemspec +5 -2
  6. metadata +3 -279
  7. data/.github/workflows/test.yml +0 -70
  8. data/.gitignore +0 -25
  9. data/spec/cli_helper.rb +0 -65
  10. data/spec/dsl_parser/context_spec.rb +0 -16
  11. data/spec/erb_helper.rb +0 -26
  12. data/spec/fixtures/for_require_relative_spec.rb +0 -3
  13. data/spec/hide_pending_formatter.rb +0 -9
  14. data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +0 -40
  15. data/spec/mysql/bigint_pk/int_pk_spec.rb +0 -47
  16. data/spec/mysql/cli/config_spec.rb +0 -210
  17. data/spec/mysql/cli/ridgepole_spec.rb +0 -447
  18. data/spec/mysql/collation/collation_spec.rb +0 -153
  19. data/spec/mysql/comment/comment_spec.rb +0 -179
  20. data/spec/mysql/default_lambda/default_lambda_spec.rb +0 -164
  21. data/spec/mysql/diff/diff2_spec.rb +0 -189
  22. data/spec/mysql/diff/diff_spec.rb +0 -168
  23. data/spec/mysql/dump/dump_class_method_spec.rb +0 -74
  24. data/spec/mysql/dump/dump_some_tables_spec.rb +0 -70
  25. data/spec/mysql/dump/dump_spec.rb +0 -74
  26. data/spec/mysql/dump/dump_unknown_column_type_spec.rb +0 -28
  27. data/spec/mysql/dump/dump_without_table_options_spec.rb +0 -34
  28. data/spec/mysql/fk/migrate_change_fk2_spec.rb +0 -47
  29. data/spec/mysql/fk/migrate_change_fk_spec.rb +0 -265
  30. data/spec/mysql/fk/migrate_create_fk_spec.rb +0 -349
  31. data/spec/mysql/fk/migrate_drop_fk_spec.rb +0 -331
  32. data/spec/mysql/fk/migrate_fk_with_column_spec.rb +0 -163
  33. data/spec/mysql/fk/migrate_ignore_fk_spec.rb +0 -70
  34. data/spec/mysql/migrate/check_orphan_index_spec.rb +0 -83
  35. data/spec/mysql/migrate/migrate_add_column2_spec.rb +0 -159
  36. data/spec/mysql/migrate/migrate_add_column_order_spec.rb +0 -242
  37. data/spec/mysql/migrate/migrate_add_column_spec.rb +0 -161
  38. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +0 -276
  39. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +0 -152
  40. data/spec/mysql/migrate/migrate_change_column2_spec.rb +0 -91
  41. data/spec/mysql/migrate/migrate_change_column3_spec.rb +0 -404
  42. data/spec/mysql/migrate/migrate_change_column4_spec.rb +0 -83
  43. data/spec/mysql/migrate/migrate_change_column5_spec.rb +0 -129
  44. data/spec/mysql/migrate/migrate_change_column6_spec.rb +0 -241
  45. data/spec/mysql/migrate/migrate_change_column7_spec.rb +0 -34
  46. data/spec/mysql/migrate/migrate_change_column8_spec.rb +0 -87
  47. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +0 -199
  48. data/spec/mysql/migrate/migrate_change_column_float_spec.rb +0 -75
  49. data/spec/mysql/migrate/migrate_change_column_spec.rb +0 -158
  50. data/spec/mysql/migrate/migrate_change_index2_spec.rb +0 -86
  51. data/spec/mysql/migrate/migrate_change_index3_spec.rb +0 -179
  52. data/spec/mysql/migrate/migrate_change_index4_spec.rb +0 -112
  53. data/spec/mysql/migrate/migrate_change_index5_spec.rb +0 -74
  54. data/spec/mysql/migrate/migrate_change_index6_spec.rb +0 -202
  55. data/spec/mysql/migrate/migrate_change_index7_spec.rb +0 -85
  56. data/spec/mysql/migrate/migrate_change_index8_spec.rb +0 -85
  57. data/spec/mysql/migrate/migrate_change_index_spec.rb +0 -235
  58. data/spec/mysql/migrate/migrate_change_table_comment_spec.rb +0 -72
  59. data/spec/mysql/migrate/migrate_change_table_option_spec.rb +0 -83
  60. data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +0 -225
  61. data/spec/mysql/migrate/migrate_create_index2_spec.rb +0 -203
  62. data/spec/mysql/migrate/migrate_create_index_spec.rb +0 -220
  63. data/spec/mysql/migrate/migrate_create_table_spec.rb +0 -123
  64. data/spec/mysql/migrate/migrate_create_table_with_ignore_spec.rb +0 -45
  65. data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +0 -43
  66. data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +0 -59
  67. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +0 -132
  68. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +0 -140
  69. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +0 -167
  70. data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +0 -52
  71. data/spec/mysql/migrate/migrate_drop_column_spec.rb +0 -158
  72. data/spec/mysql/migrate/migrate_drop_index_spec.rb +0 -160
  73. data/spec/mysql/migrate/migrate_drop_table_spec.rb +0 -123
  74. data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +0 -27
  75. data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +0 -37
  76. data/spec/mysql/migrate/migrate_empty_spec.rb +0 -78
  77. data/spec/mysql/migrate/migrate_execute_spec.rb +0 -288
  78. data/spec/mysql/migrate/migrate_ignore_column_spec.rb +0 -98
  79. data/spec/mysql/migrate/migrate_ignore_index_spec.rb +0 -92
  80. data/spec/mysql/migrate/migrate_log_file_spec.rb +0 -125
  81. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +0 -145
  82. data/spec/mysql/migrate/migrate_noop_spec.rb +0 -234
  83. data/spec/mysql/migrate/migrate_primary_key_spec.rb +0 -104
  84. data/spec/mysql/migrate/migrate_rename_column_spec.rb +0 -184
  85. data/spec/mysql/migrate/migrate_rename_table_spec.rb +0 -241
  86. data/spec/mysql/migrate/migrate_same_default_null_spec.rb +0 -77
  87. data/spec/mysql/migrate/migrate_same_spec.rb +0 -82
  88. data/spec/mysql/migrate/migrate_script_error_spec.rb +0 -91
  89. data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +0 -39
  90. data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +0 -145
  91. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +0 -140
  92. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +0 -141
  93. data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +0 -307
  94. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +0 -153
  95. data/spec/mysql/migrate/migrate_with_tables_spec.rb +0 -149
  96. data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +0 -60
  97. data/spec/mysql/ridgepole_test_database.sql +0 -2
  98. data/spec/mysql/ridgepole_test_tables.sql +0 -79
  99. data/spec/mysql/ridgepole_test_tables_unknown_column_type.sql +0 -17
  100. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +0 -131
  101. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +0 -59
  102. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +0 -133
  103. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +0 -100
  104. data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +0 -43
  105. data/spec/mysql57/json/add_json_column_spec.rb +0 -35
  106. data/spec/mysql57/json/change_json_column_spec.rb +0 -102
  107. data/spec/mysql57/json/drop_json_column_spec.rb +0 -35
  108. data/spec/mysql57/virtual/add_virtual_column_spec.rb +0 -37
  109. data/spec/mysql57/virtual/change_virtual_column_spec.rb +0 -40
  110. data/spec/mysql57/virtual/drop_virtual_column_spec.rb +0 -37
  111. data/spec/postgresql/diff/diff_spec.rb +0 -216
  112. data/spec/postgresql/dump/dump_spec.rb +0 -69
  113. data/spec/postgresql/fk/migrate_change_fk_spec.rb +0 -115
  114. data/spec/postgresql/fk/migrate_create_fk_spec.rb +0 -176
  115. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +0 -197
  116. data/spec/postgresql/migrate/migrate_add_column_spec.rb +0 -203
  117. data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +0 -25
  118. data/spec/postgresql/migrate/migrate_bigint_spec.rb +0 -53
  119. data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +0 -38
  120. data/spec/postgresql/migrate/migrate_change_column_spec.rb +0 -185
  121. data/spec/postgresql/migrate/migrate_change_index_spec.rb +0 -164
  122. data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +0 -114
  123. data/spec/postgresql/migrate/migrate_create_table_spec.rb +0 -120
  124. data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +0 -112
  125. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +0 -163
  126. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +0 -166
  127. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +0 -59
  128. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +0 -158
  129. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +0 -122
  130. data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +0 -64
  131. data/spec/postgresql/migrate/migrate_primary_key2_spec.rb +0 -73
  132. data/spec/postgresql/migrate/migrate_primary_key_spec.rb +0 -99
  133. data/spec/postgresql/migrate/migrate_references_spec.rb +0 -90
  134. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +0 -155
  135. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +0 -175
  136. data/spec/postgresql/migrate/migrate_same_spec.rb +0 -77
  137. data/spec/postgresql/ridgepole_test_database.sql +0 -16
  138. data/spec/postgresql/ridgepole_test_tables.sql +0 -75
  139. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +0 -59
  140. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +0 -134
  141. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +0 -100
  142. data/spec/processing_for_ci.rb +0 -13
  143. data/spec/spec_condition.rb +0 -58
  144. data/spec/spec_const.rb +0 -20
  145. data/spec/spec_helper.rb +0 -173
@@ -1,176 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when create fk' do
5
- let(:actual_dsl) do
6
- erbh(<<-ERB)
7
- create_table "child", force: :cascade do |t|
8
- t.integer "parent_id"
9
- t.index ["parent_id"], name: "par_id"
10
- end
11
-
12
- create_table "parent", force: :cascade do |t|
13
- end
14
- ERB
15
- end
16
-
17
- let(:expected_dsl) do
18
- actual_dsl + <<-RUBY
19
- add_foreign_key "child", "parent", name: "child_ibfk_1"
20
- RUBY
21
- end
22
-
23
- before { subject.diff(actual_dsl).migrate }
24
- subject { client }
25
-
26
- it {
27
- delta = subject.diff(expected_dsl)
28
- expect(delta.differ?).to be_truthy
29
- expect(subject.dump).to match_ruby actual_dsl
30
- delta.migrate
31
- expect(subject.dump).to match_ruby expected_dsl
32
- }
33
-
34
- it {
35
- delta = client(bulk_change: true).diff(expected_dsl)
36
- expect(delta.differ?).to be_truthy
37
- expect(subject.dump).to match_ruby actual_dsl
38
- expect(delta.script).to match_fuzzy <<-RUBY
39
- add_foreign_key("child", "parent", **{:name=>"child_ibfk_1"})
40
- RUBY
41
- delta.migrate
42
- expect(subject.dump).to match_ruby expected_dsl
43
- }
44
- end
45
-
46
- context 'when create fk when create table' do
47
- let(:dsl) do
48
- erbh(<<-ERB)
49
- # Define parent before child
50
- create_table "parent", force: :cascade do |t|
51
- end
52
-
53
- create_table "child", force: :cascade do |t|
54
- t.integer "parent_id", unsigned: true
55
- t.index ["parent_id"], name: "par_id"
56
- end
57
-
58
- add_foreign_key "child", "parent", name: "child_ibfk_1"
59
- ERB
60
- end
61
-
62
- let(:sorted_dsl) do
63
- erbh(<<-ERB)
64
- create_table "child", force: :cascade do |t|
65
- t.integer "parent_id"
66
- t.index ["parent_id"], name: "par_id"
67
- end
68
-
69
- create_table "parent", force: :cascade do |t|
70
- end
71
-
72
- add_foreign_key "child", "parent", name: "child_ibfk_1"
73
- ERB
74
- end
75
-
76
- before { client.diff('').migrate }
77
- subject { client }
78
-
79
- it {
80
- delta = subject.diff(dsl)
81
- expect(delta.differ?).to be_truthy
82
- expect(subject.dump).to match_fuzzy ''
83
- delta.migrate
84
- expect(subject.dump).to match_fuzzy sorted_dsl
85
- }
86
- end
87
-
88
- context 'already defined' do
89
- let(:dsl) do
90
- erbh(<<-ERB)
91
- # Define parent before child
92
- create_table "parent", force: :cascade do |t|
93
- end
94
-
95
- create_table "child", force: :cascade do |t|
96
- t.integer "parent_id", unsigned: true
97
- t.index ["parent_id"], name: "par_id"
98
- end
99
-
100
- add_foreign_key "child", "parent", name: "child_ibfk_1"
101
-
102
- add_foreign_key "child", "parent", name: "child_ibfk_1"
103
- ERB
104
- end
105
-
106
- subject { client }
107
-
108
- it {
109
- expect do
110
- subject.diff(dsl)
111
- end.to raise_error('Foreign Key `child(child_ibfk_1)` already defined')
112
- }
113
- end
114
-
115
- context 'when create fk without name' do
116
- let(:actual_dsl) do
117
- erbh(<<-ERB)
118
- create_table "child", force: :cascade do |t|
119
- t.integer "parent_id"
120
- t.index ["parent_id"], name: "par_id"
121
- end
122
-
123
- create_table "parent", force: :cascade do |t|
124
- end
125
- ERB
126
- end
127
-
128
- let(:expected_dsl) do
129
- actual_dsl + <<-RUBY
130
- add_foreign_key "child", "parent"
131
- RUBY
132
- end
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 match_ruby actual_dsl
141
- delta.migrate
142
- expect(subject.dump).to match_ruby expected_dsl
143
- }
144
-
145
- it {
146
- delta = client(bulk_change: true).diff(expected_dsl)
147
- expect(delta.differ?).to be_truthy
148
- expect(subject.dump).to match_ruby actual_dsl
149
- expect(delta.script).to match_fuzzy <<-RUBY
150
- add_foreign_key("child", "parent", **{})
151
- RUBY
152
- delta.migrate
153
- expect(subject.dump).to match_ruby expected_dsl
154
- }
155
- end
156
-
157
- context 'orphan fk' do
158
- let(:dsl) do
159
- erbh(<<-ERB)
160
- # Define parent before child
161
- create_table "parent", force: :cascade do |t|
162
- end
163
-
164
- add_foreign_key "child", "parent", name: "child_ibfk_1"
165
- ERB
166
- end
167
-
168
- subject { client }
169
-
170
- it {
171
- expect do
172
- subject.diff(dsl)
173
- end.to raise_error('Table `child` to create the foreign key is not defined: child_ibfk_1')
174
- }
175
- end
176
- end
@@ -1,197 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when drop fk' do
5
- let(:actual_dsl) do
6
- erbh(<<-ERB)
7
- create_table "parent", force: :cascade do |t|
8
- end
9
-
10
- create_table "child", force: :cascade do |t|
11
- t.integer "parent_id"
12
- t.index ["parent_id"], name: "par_id"
13
- end
14
-
15
- add_foreign_key "child", "parent", name: "child_ibfk_1"
16
- ERB
17
- end
18
-
19
- let(:sorted_actual_dsl) do
20
- expected_dsl + <<-RUBY
21
- add_foreign_key "child", "parent", name: "child_ibfk_1"
22
- RUBY
23
- end
24
-
25
- let(:expected_dsl) do
26
- erbh(<<-ERB)
27
- create_table "child", force: :cascade do |t|
28
- t.integer "parent_id"
29
- t.index ["parent_id"], name: "par_id"
30
- end
31
-
32
- create_table "parent", force: :cascade do |t|
33
- end
34
- ERB
35
- end
36
-
37
- before { subject.diff(actual_dsl).migrate }
38
- subject { client }
39
-
40
- it {
41
- delta = subject.diff(expected_dsl)
42
- expect(delta.differ?).to be_truthy
43
- expect(subject.dump).to match_fuzzy sorted_actual_dsl
44
- delta.migrate
45
- expect(subject.dump).to match_ruby expected_dsl
46
- }
47
-
48
- it {
49
- delta = client(bulk_change: true).diff(expected_dsl)
50
- expect(delta.differ?).to be_truthy
51
- expect(subject.dump).to match_fuzzy sorted_actual_dsl
52
- expect(delta.script).to match_fuzzy <<-RUBY
53
- remove_foreign_key("child", name: "child_ibfk_1")
54
- RUBY
55
- delta.migrate
56
- expect(subject.dump).to match_ruby expected_dsl
57
- }
58
- end
59
-
60
- context 'when drop fk when drop table' do
61
- let(:dsl) do
62
- erbh(<<-ERB)
63
- create_table "parent", force: :cascade do |t|
64
- end
65
-
66
- create_table "child", force: :cascade do |t|
67
- t.integer "parent_id", unsigned: true
68
- t.index ["parent_id"], name: "par_id"
69
- end
70
-
71
- add_foreign_key "child", "parent", name: "child_ibfk_1"
72
- ERB
73
- end
74
-
75
- let(:sorted_dsl) do
76
- erbh(<<-ERB)
77
- create_table "child", force: :cascade do |t|
78
- t.integer "parent_id"
79
- t.index ["parent_id"], name: "par_id"
80
- end
81
-
82
- create_table "parent", force: :cascade do |t|
83
- end
84
-
85
- add_foreign_key "child", "parent", name: "child_ibfk_1"
86
- ERB
87
- end
88
-
89
- before { subject.diff(dsl).migrate }
90
- subject { client }
91
-
92
- it {
93
- delta = subject.diff('')
94
- expect(delta.differ?).to be_truthy
95
- expect(subject.dump).to match_fuzzy sorted_dsl
96
- delta.migrate
97
- expect(subject.dump).to match_fuzzy ''
98
- }
99
- end
100
-
101
- context 'when drop fk without name' do
102
- let(:actual_dsl) do
103
- erbh(<<-ERB)
104
- create_table "parent", force: :cascade do |t|
105
- end
106
-
107
- create_table "child", force: :cascade do |t|
108
- t.integer "parent_id"
109
- t.index ["parent_id"], name: "par_id"
110
- end
111
-
112
- add_foreign_key "child", "parent"
113
- ERB
114
- end
115
-
116
- let(:sorted_actual_dsl) do
117
- expected_dsl + <<-RUBY
118
- add_foreign_key "child", "parent"
119
- RUBY
120
- end
121
-
122
- let(:expected_dsl) do
123
- erbh(<<-ERB)
124
- create_table "child", force: :cascade do |t|
125
- t.integer "parent_id"
126
- t.index ["parent_id"], name: "par_id"
127
- end
128
-
129
- create_table "parent", force: :cascade do |t|
130
- end
131
- ERB
132
- end
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 match_fuzzy sorted_actual_dsl
141
- delta.migrate
142
- expect(subject.dump).to match_ruby expected_dsl
143
- }
144
-
145
- it {
146
- delta = client(bulk_change: true).diff(expected_dsl)
147
- expect(delta.differ?).to be_truthy
148
- expect(subject.dump).to match_fuzzy sorted_actual_dsl
149
- expect(delta.script).to match_fuzzy <<-RUBY
150
- remove_foreign_key("child", "parent")
151
- RUBY
152
- delta.migrate
153
- expect(subject.dump).to match_ruby expected_dsl
154
- }
155
- end
156
-
157
- context 'when drop fk when drop table without name' do
158
- let(:dsl) do
159
- erbh(<<-ERB)
160
- create_table "parent", force: :cascade do |t|
161
- end
162
-
163
- create_table "child", force: :cascade do |t|
164
- t.integer "parent_id", unsigned: true
165
- t.index ["parent_id"], name: "par_id"
166
- end
167
-
168
- add_foreign_key "child", "parent"
169
- ERB
170
- end
171
-
172
- let(:sorted_dsl) do
173
- erbh(<<-ERB)
174
- create_table "child", force: :cascade do |t|
175
- t.integer "parent_id"
176
- t.index ["parent_id"], name: "par_id"
177
- end
178
-
179
- create_table "parent", force: :cascade do |t|
180
- end
181
-
182
- add_foreign_key "child", "parent"
183
- ERB
184
- end
185
-
186
- before { subject.diff(dsl).migrate }
187
- subject { client }
188
-
189
- it {
190
- delta = subject.diff('')
191
- expect(delta.differ?).to be_truthy
192
- expect(subject.dump).to match_fuzzy sorted_dsl
193
- delta.migrate
194
- expect(subject.dump).to match_fuzzy ''
195
- }
196
- end
197
- end
@@ -1,203 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when add column' do
5
- let(:actual_dsl) do
6
- erbh(<<-ERB)
7
- create_table "clubs", force: :cascade do |t|
8
- t.string "name", limit: 255, default: "", null: false
9
- t.index ["name"], name: "idx_name", unique: true
10
- end
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
- t.index ["dept_no"], name: "idx_dept_emp_dept_no"
22
- t.index ["emp_no"], name: "idx_dept_emp_emp_no"
23
- end
24
-
25
- create_table "dept_manager", id: false, force: :cascade do |t|
26
- t.string "dept_no", limit: 4, null: false
27
- t.integer "emp_no", null: false
28
- t.date "from_date", null: false
29
- t.date "to_date", null: false
30
- t.index ["dept_no"], name: "idx_dept_manager_dept_no"
31
- t.index ["emp_no"], name: "idx_dept_manager_emp_no"
32
- end
33
-
34
- create_table "employee_clubs", force: :cascade do |t|
35
- t.integer "emp_no", null: false
36
- t.integer "club_id", null: false
37
- t.index ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id"
38
- end
39
-
40
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
41
- t.date "birth_date", null: false
42
- t.string "first_name", limit: 14, null: false
43
- t.string "last_name", limit: 16, null: false
44
- t.date "hire_date", null: false
45
- end
46
-
47
- create_table "salaries", id: false, force: :cascade do |t|
48
- t.integer "emp_no", null: false
49
- t.integer "salary", null: false
50
- t.date "from_date", null: false
51
- t.date "to_date", null: false
52
- t.index ["emp_no"], name: "idx_salaries_emp_no"
53
- end
54
-
55
- create_table "titles", id: false, force: :cascade do |t|
56
- t.integer "emp_no", null: false
57
- t.string "title", limit: 50, null: false
58
- t.date "from_date", null: false
59
- t.date "to_date"
60
- t.index ["emp_no"], name: "idx_titles_emp_no"
61
- end
62
- ERB
63
- end
64
-
65
- let(:expected_dsl) do
66
- erbh(<<-ERB)
67
- create_table "clubs", force: :cascade do |t|
68
- t.string "name", limit: 255, default: "", null: false
69
- t.index ["name"], name: "idx_name", unique: true
70
- end
71
-
72
- create_table "departments", primary_key: "dept_no", force: :cascade do |t|
73
- t.string "dept_name", limit: 40, null: false
74
- end
75
-
76
- create_table "dept_emp", id: false, force: :cascade do |t|
77
- t.integer "emp_no", null: false
78
- t.string "dept_no", limit: 4, null: false
79
- t.date "from_date", null: false
80
- t.date "to_date", null: false
81
- t.index ["dept_no"], name: "idx_dept_emp_dept_no"
82
- t.index ["emp_no"], name: "idx_dept_emp_emp_no"
83
- end
84
-
85
- create_table "dept_manager", id: false, force: :cascade do |t|
86
- t.string "dept_no", limit: 4, null: false
87
- t.integer "emp_no", null: false
88
- t.date "from_date", null: false
89
- t.date "to_date", null: false
90
- t.index ["dept_no"], name: "idx_dept_manager_dept_no"
91
- t.index ["emp_no"], name: "idx_dept_manager_emp_no"
92
- end
93
-
94
- create_table "employee_clubs", force: :cascade do |t|
95
- t.integer "emp_no", null: false
96
- t.integer "club_id", null: false
97
- t.string "any_col", limit: 255, null: false
98
- t.index ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id"
99
- end
100
-
101
- create_table "employees", primary_key: "emp_no", force: :cascade do |t|
102
- t.date "birth_date", null: false
103
- t.string "first_name", limit: 14, null: false
104
- t.string "last_name", limit: 16, null: false
105
- t.date "hire_date", null: false
106
- t.integer "age", null: false
107
- t.date "updated_at"
108
- end
109
-
110
- create_table "salaries", id: false, force: :cascade do |t|
111
- t.integer "emp_no", null: false
112
- t.integer "salary", null: false
113
- t.date "from_date", null: false
114
- t.date "to_date", null: false
115
- t.index ["emp_no"], name: "idx_salaries_emp_no"
116
- end
117
-
118
- create_table "titles", id: false, force: :cascade do |t|
119
- t.integer "emp_no", null: false
120
- t.string "title", limit: 50, null: false
121
- t.date "from_date", null: false
122
- t.date "to_date"
123
- t.serial "title_no", null: false
124
- t.bigserial "title_bigno", null: false
125
- t.index ["emp_no"], name: "idx_titles_emp_no"
126
- end
127
- ERB
128
- end
129
-
130
- before { subject.diff(actual_dsl).migrate }
131
- subject { client }
132
-
133
- it {
134
- delta = subject.diff(expected_dsl)
135
- expect(delta.differ?).to be_truthy
136
- expect(subject.dump).to match_ruby actual_dsl
137
- delta.migrate
138
- expect(subject.dump).to match_ruby expected_dsl
139
- }
140
-
141
- it {
142
- delta = client(bulk_change: true).diff(expected_dsl)
143
- expect(delta.differ?).to be_truthy
144
- expect(subject.dump).to match_ruby actual_dsl
145
- expect(delta.script).to match_fuzzy <<-RUBY
146
- change_table("employee_clubs", bulk: true) do |t|
147
- t.column("any_col", :string, **{:limit=>255, :null=>false})
148
- end
149
-
150
- change_table("employees", bulk: true) do |t|
151
- t.column("age", :integer, **{:null=>false})
152
- t.column("updated_at", :date, **{})
153
- end
154
-
155
- change_table("titles", bulk: true) do |t|
156
- t.column("title_no", :serial, **{:null=>false})
157
- t.column("title_bigno", :bigserial, **{:null=>false})
158
- end
159
- RUBY
160
- delta.migrate
161
- expect(subject.dump).to match_ruby expected_dsl
162
- }
163
- end
164
-
165
- context 'when add column (int/noop)' do
166
- let(:actual_dsl) do
167
- erbh(<<-ERB)
168
- create_table "dept_emp", id: false, force: :cascade do |t|
169
- t.integer "emp_no", null: false
170
- t.string "dept_no", limit: 4, null: false
171
- t.date "from_date", null: false
172
- t.date "to_date", null: false
173
- end
174
- ERB
175
- end
176
-
177
- let(:expected_dsl) do
178
- erbh(<<-ERB)
179
- create_table "dept_emp", id: false, force: :cascade do |t|
180
- t.integer "emp_no", null: false
181
- t.integer "emp_no2", null: false
182
- t.string "dept_no", limit: 4, null: false
183
- t.date "from_date", null: false
184
- t.date "to_date", null: false
185
- end
186
- ERB
187
- end
188
-
189
- before { subject.diff(actual_dsl).migrate }
190
- subject { client }
191
-
192
- it {
193
- delta = subject.diff(expected_dsl)
194
- expect(delta.differ?).to be_truthy
195
- expect(subject.dump).to match_ruby actual_dsl
196
- migrated, sql = delta.migrate(noop: true)
197
- expect(migrated).to be_truthy
198
- expect(subject.dump).to match_ruby actual_dsl
199
-
200
- expect(sql).to match_fuzzy('ALTER TABLE "dept_emp" ADD "emp_no2" integer NOT NULL')
201
- }
202
- end
203
- end