ridgepole 0.9.3 → 1.0.0

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