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,79 +0,0 @@
1
- USE `ridgepole_test`;
2
-
3
- DROP TABLE IF EXISTS `clubs`;
4
- CREATE TABLE `clubs` (
5
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
6
- `name` varchar(255) NOT NULL DEFAULT '',
7
- PRIMARY KEY (`id`),
8
- UNIQUE KEY `idx_name` (`name`)
9
- );
10
-
11
- DROP TABLE IF EXISTS `departments`;
12
- CREATE TABLE `departments` (
13
- `dept_no` char(4) NOT NULL,
14
- `dept_name` varchar(40) NOT NULL,
15
- PRIMARY KEY (`dept_no`),
16
- UNIQUE KEY `dept_name` (`dept_name`)
17
- );
18
-
19
- DROP TABLE IF EXISTS `dept_emp`;
20
- CREATE TABLE `dept_emp` (
21
- `emp_no` int(11) NOT NULL,
22
- `dept_no` char(4) NOT NULL,
23
- `from_date` date NOT NULL,
24
- `to_date` date NOT NULL,
25
- PRIMARY KEY (`emp_no`,`dept_no`),
26
- KEY `emp_no` (`emp_no`),
27
- KEY `dept_no` (`dept_no`)
28
- );
29
-
30
- DROP TABLE IF EXISTS `dept_manager`;
31
- CREATE TABLE `dept_manager` (
32
- `dept_no` char(4) NOT NULL,
33
- `emp_no` int(11) NOT NULL,
34
- `from_date` date NOT NULL,
35
- `to_date` date NOT NULL,
36
- PRIMARY KEY (`emp_no`,`dept_no`),
37
- KEY `emp_no` (`emp_no`),
38
- KEY `dept_no` (`dept_no`)
39
- );
40
-
41
- DROP TABLE IF EXISTS `employee_clubs`;
42
- CREATE TABLE `employee_clubs` (
43
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
44
- `emp_no` int(10) unsigned NOT NULL,
45
- `club_id` int(10) unsigned NOT NULL,
46
- PRIMARY KEY (`id`),
47
- KEY `idx_emp_no_club_id` (`emp_no`,`club_id`) USING BTREE
48
- );
49
-
50
- DROP TABLE IF EXISTS `employees`;
51
- CREATE TABLE `employees` (
52
- `emp_no` int(11) NOT NULL,
53
- `birth_date` date NOT NULL,
54
- `first_name` varchar(14) NOT NULL,
55
- `last_name` varchar(16) NOT NULL,
56
- `gender` enum('M','F') NOT NULL,
57
- `hire_date` date NOT NULL,
58
- PRIMARY KEY (`emp_no`)
59
- );
60
-
61
- DROP TABLE IF EXISTS `salaries`;
62
- CREATE TABLE `salaries` (
63
- `emp_no` int(11) NOT NULL,
64
- `salary` int(11) NOT NULL,
65
- `from_date` date NOT NULL,
66
- `to_date` date NOT NULL,
67
- PRIMARY KEY (`emp_no`,`from_date`),
68
- KEY `emp_no` (`emp_no`)
69
- );
70
-
71
- DROP TABLE IF EXISTS `titles`;
72
- CREATE TABLE `titles` (
73
- `emp_no` int(11) NOT NULL,
74
- `title` varchar(50) NOT NULL,
75
- `from_date` date NOT NULL,
76
- `to_date` date DEFAULT NULL,
77
- PRIMARY KEY (`emp_no`,`title`,`from_date`),
78
- KEY `emp_no` (`emp_no`)
79
- );
@@ -1,17 +0,0 @@
1
- USE `ridgepole_test`;
2
-
3
- DROP TABLE IF EXISTS `clubs`;
4
- CREATE TABLE `clubs` (
5
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
6
- `name` varchar(255) NOT NULL DEFAULT '',
7
- PRIMARY KEY (`id`),
8
- UNIQUE KEY `idx_name` (`name`)
9
- );
10
-
11
- DROP TABLE IF EXISTS `places`;
12
- CREATE TABLE `places` (
13
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
14
- `location` geometry NOT NULL,
15
- PRIMARY KEY (`id`),
16
- KEY `id` (`id`)
17
- );
@@ -1,131 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client (with new text/blob types)' do
4
- context 'when use new types' do
5
- subject { client }
6
-
7
- it do
8
- table_def = <<-RUBY
9
- create_table :foos, id: :unsigned_integer do |t|
10
- t.blob :blob
11
- t.tinyblob :tiny_blob
12
- t.mediumblob :medium_blob
13
- t.longblob :long_blob
14
- t.tinytext :tiny_text
15
- t.mediumtext :medium_text
16
- t.longtext :long_text
17
- t.unsigned_decimal :unsigned_decimal
18
- t.unsigned_float :unsigned_float
19
- t.unsigned_bigint :unsigned_bigint
20
- t.unsigned_integer :unsigned_integer
21
- end
22
- RUBY
23
- delta = subject.diff(table_def)
24
-
25
- expect(delta.differ?).to be_truthy
26
- delta.migrate
27
-
28
- expect(subject.dump).to match_ruby erbh(<<-ERB)
29
- create_table "foos", <%= i cond(">= 6.1", { id: { type: :integer, unsigned: true } }, { id: :integer, unsigned: true }) %>, force: :cascade do |t|
30
- t.binary "blob"
31
- t.<%= cond('< 6.0.0.beta2', :blob, :binary) %> "tiny_blob", <%= i cond('< 6.0.0.beta2', {limit: 255}, {size: :tiny}) %>
32
- t.binary "medium_blob", <%= i cond('< 6.0.0.beta2', {limit: 16777215}, {size: :medium}) %>
33
- t.binary "long_blob", <%= i cond('< 6.0.0.beta2', {limit: 4294967295}, {size: :long}) %>
34
- t.text "tiny_text", <%= i cond('< 6.0.0.beta2', {limit: 255}, {size: :tiny}) %>
35
- t.text "medium_text", <%= i cond('< 6.0.0.beta2', {limit: 16777215}, {size: :medium}) %>
36
- t.text "long_text", <%= i cond('< 6.0.0.beta2', {limit: 4294967295}, {size: :long}) %>
37
- t.decimal "unsigned_decimal", precision: 10, unsigned: true
38
- t.float "unsigned_float", <%= i cond('< 5.2.0.beta2', limit: 24) %>, unsigned: true
39
- t.bigint "unsigned_bigint", unsigned: true
40
- t.integer "unsigned_integer", unsigned: true
41
- end
42
- ERB
43
-
44
- expect(subject.diff(table_def).differ?).to be_falsey
45
- end
46
- end
47
-
48
- context 'when compare new types', condition: '< 6.0.0.beta2' do
49
- subject { client }
50
-
51
- before do
52
- subject.diff(<<-RUBY).migrate
53
- create_table :foos do |t|
54
- t.blob :blob
55
- t.tinyblob :tiny_blob
56
- t.mediumblob :medium_blob
57
- t.longblob :long_blob
58
- t.tinytext :tiny_text
59
- t.mediumtext :medium_text
60
- t.longtext :long_text
61
- t.unsigned_decimal :unsigned_decimal
62
- t.unsigned_float :unsigned_float
63
- t.unsigned_bigint :unsigned_bigint
64
- t.unsigned_integer :unsigned_integer
65
- end
66
- RUBY
67
- end
68
-
69
- it do
70
- delta = subject.diff(<<-RUBY)
71
- create_table :foos do |t|
72
- t.blob :blob
73
- t.tinyblob :tiny_blob
74
- t.mediumblob :medium_blob
75
- t.longblob :long_blob
76
- t.tinytext :tiny_text
77
- t.mediumtext :medium_text
78
- t.longtext :long_text
79
- t.unsigned_decimal :unsigned_decimal
80
- t.unsigned_float :unsigned_float
81
- t.unsigned_bigint :unsigned_bigint
82
- t.unsigned_integer :unsigned_integer
83
- end
84
- RUBY
85
-
86
- expect(delta.differ?).to be_falsey
87
- end
88
- end
89
-
90
- context 'when compare new types', condition: '>= 6.0.0.beta2' do
91
- subject { client }
92
-
93
- before do
94
- subject.diff(<<-RUBY).migrate
95
- create_table "foos", force: :cascade do |t|
96
- t.binary "blob"
97
- t.binary "tiny_blob", size: :tiny
98
- t.binary "medium_blob", size: :medium
99
- t.binary "long_blob", size: :long
100
- t.text "tiny_text", size: :tiny
101
- t.text "medium_text", size: :medium
102
- t.text "long_text", size: :long
103
- t.decimal "unsigned_decimal", precision: 10, unsigned: true
104
- t.float "unsigned_float", unsigned: true
105
- t.bigint "unsigned_bigint", unsigned: true
106
- t.integer "unsigned_integer", unsigned: true
107
- end
108
- RUBY
109
- end
110
-
111
- it do
112
- delta = subject.diff(<<-RUBY)
113
- create_table "foos", force: :cascade do |t|
114
- t.binary "blob"
115
- t.binary "tiny_blob", size: :tiny
116
- t.binary "medium_blob", size: :medium
117
- t.binary "long_blob", size: :long
118
- t.text "tiny_text", size: :tiny
119
- t.text "medium_text", size: :medium
120
- t.text "long_text", size: :long
121
- t.decimal "unsigned_decimal", precision: 10, unsigned: true
122
- t.float "unsigned_float", unsigned: true
123
- t.bigint "unsigned_bigint", unsigned: true
124
- t.integer "unsigned_integer", unsigned: true
125
- end
126
- RUBY
127
-
128
- expect(delta.differ?).to be_falsey
129
- end
130
- end
131
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when change fk' do
5
- let(:actual_dsl) do
6
- erbh(<<-ERB)
7
- create_table "parent", id: :integer, 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: "fk_rails_e74ce85cbc", on_delete: :cascade
16
- ERB
17
- end
18
-
19
- let(:sorted_actual_dsl) do
20
- erbh(<<-ERB)
21
- create_table "child", force: :cascade do |t|
22
- t.integer "parent_id"
23
- t.index ["parent_id"], name: "par_id"
24
- end
25
-
26
- create_table "parent", id: :integer, force: :cascade do |t|
27
- end
28
-
29
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc", on_delete: :cascade
30
- ERB
31
- end
32
-
33
- let(:expected_dsl) do
34
- erbh(<<-ERB)
35
- create_table "child", force: :cascade do |t|
36
- t.integer "parent_id"
37
- t.index ["parent_id"], name: "par_id"
38
- end
39
-
40
- create_table "parent", id: :integer, force: :cascade do |t|
41
- end
42
-
43
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
44
- ERB
45
- end
46
-
47
- before { subject.diff(actual_dsl).migrate }
48
-
49
- subject { client(dump_with_default_fk_name: true) }
50
-
51
- it {
52
- delta = subject.diff(expected_dsl)
53
- expect(delta.differ?).to be_truthy
54
- expect(subject.dump).to match_fuzzy sorted_actual_dsl
55
- delta.migrate
56
- expect(subject.dump).to match_ruby expected_dsl
57
- }
58
- end
59
- end
@@ -1,133 +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", id: :integer, 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: "fk_rails_e74ce85cbc"
20
- RUBY
21
- end
22
-
23
- before { subject.diff(actual_dsl).migrate }
24
- subject { client(dump_with_default_fk_name: true) }
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, dump_with_default_fk_name: 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=>"fk_rails_e74ce85cbc"})
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", id: :integer, force: :cascade do |t|
51
- end
52
-
53
- create_table "child", force: :cascade do |t|
54
- t.integer "parent_id"
55
- t.index ["parent_id"], name: "par_id"
56
- end
57
-
58
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
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", id: :integer, force: :cascade do |t|
70
- end
71
-
72
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
73
- ERB
74
- end
75
-
76
- subject { client(dump_with_default_fk_name: true) }
77
-
78
- it {
79
- delta = subject.diff(dsl)
80
- expect(delta.differ?).to be_truthy
81
- expect(subject.dump).to match_fuzzy ''
82
- delta.migrate
83
- expect(subject.dump).to match_fuzzy sorted_dsl
84
- }
85
- end
86
-
87
- context 'already defined' do
88
- let(:dsl) do
89
- erbh(<<-ERB)
90
- # Define parent before child
91
- create_table "parent", id: :integer, force: :cascade do |t|
92
- end
93
-
94
- create_table "child", force: :cascade do |t|
95
- t.integer "parent_id", unsigned: true
96
- t.index ["parent_id"], name: "par_id"
97
- end
98
-
99
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
100
-
101
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
102
- ERB
103
- end
104
-
105
- subject { client(dump_with_default_fk_name: true) }
106
-
107
- it {
108
- expect do
109
- subject.diff(dsl)
110
- end.to raise_error('Foreign Key `child(fk_rails_e74ce85cbc)` already defined')
111
- }
112
- end
113
-
114
- context 'orphan fk' do
115
- let(:dsl) do
116
- erbh(<<-ERB)
117
- # Define parent before child
118
- create_table "parent", id: :integer, force: :cascade do |t|
119
- end
120
-
121
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
122
- ERB
123
- end
124
-
125
- subject { client(dump_with_default_fk_name: true) }
126
-
127
- it {
128
- expect do
129
- subject.diff(dsl)
130
- end.to raise_error('Table `child` to create the foreign key is not defined: fk_rails_e74ce85cbc')
131
- }
132
- end
133
- end
@@ -1,100 +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", id: :integer, 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: "fk_rails_e74ce85cbc"
16
- ERB
17
- end
18
-
19
- let(:sorted_actual_dsl) do
20
- expected_dsl + <<-RUBY
21
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
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", id: :integer, force: :cascade do |t|
33
- end
34
- ERB
35
- end
36
-
37
- before { subject.diff(actual_dsl).migrate }
38
- subject { client(dump_with_default_fk_name: true) }
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, dump_with_default_fk_name: 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: "fk_rails_e74ce85cbc")
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", id: :integer, force: :cascade do |t|
64
- end
65
-
66
- create_table "child", force: :cascade do |t|
67
- t.integer "parent_id"
68
- t.index ["parent_id"], name: "par_id"
69
- end
70
-
71
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
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", id: :integer, force: :cascade do |t|
83
- end
84
-
85
- add_foreign_key "child", "parent", name: "fk_rails_e74ce85cbc"
86
- ERB
87
- end
88
-
89
- before { subject.diff(dsl).migrate }
90
- subject { client(dump_with_default_fk_name: true) }
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
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate (with index)' do
4
- context 'when create table with auto increment column' do
5
- let(:actual_dsl) { '' }
6
-
7
- let(:expected_dsl) do
8
- erbh(<<-ERB)
9
- create_table "dept_emp", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
10
- t.integer "emp_no", null: false
11
- t.integer "dept_no", null: false, auto_increment: true
12
- t.date "from_date", null: false
13
- t.date "to_date", null: false
14
- t.index ["dept_no"], name: "dept_no"
15
- t.index ["emp_no"], name: "emp_no"
16
- end
17
- ERB
18
- end
19
-
20
- before { subject.diff(actual_dsl).migrate }
21
- subject { client(create_table_with_index: true, mysql_dump_auto_increment: true) }
22
-
23
- it {
24
- delta = subject.diff(expected_dsl)
25
- expect(delta.differ?).to be_truthy
26
-
27
- expect(delta.script).to match_fuzzy erbh(<<-ERB)
28
- create_table("dept_emp", **{:primary_key=>["emp_no", "dept_no"]}) do |t|
29
- t.column("emp_no", :"integer", **{:null=>false, :limit=>4})
30
- t.column("dept_no", :"integer", **{:null=>false, :auto_increment=>true, :limit=>4})
31
- t.column("from_date", :"date", **{:null=>false})
32
- t.column("to_date", :"date", **{:null=>false})
33
- t.index(["dept_no"], **{:name=>"dept_no"})
34
- t.index(["emp_no"], **{:name=>"emp_no"})
35
- end
36
- ERB
37
-
38
- expect(subject.dump).to match_ruby actual_dsl
39
- delta.migrate
40
- expect(subject.dump).to match_ruby expected_dsl
41
- }
42
- end
43
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when add virtual column' do
5
- let(:actual_dsl) do
6
- erbh(<<-ERB)
7
- create_table "books", force: :cascade do |t|
8
- t.string "title", null: false
9
- t.index ["title"], name: "index_books_on_title"
10
- end
11
- ERB
12
- end
13
-
14
- let(:expected_dsl) do
15
- erbh(<<-ERB)
16
- create_table "books", force: :cascade do |t|
17
- t.string "title", null: false
18
- t.json "attrs", null: false
19
- t.index ["title"], name: "index_books_on_title"
20
- end
21
- ERB
22
- end
23
-
24
- before { subject.diff(actual_dsl).migrate }
25
- subject { client }
26
-
27
- it {
28
- delta = subject.diff(expected_dsl)
29
- expect(delta.differ?).to be_truthy
30
- expect(subject.dump).to match_ruby actual_dsl
31
- delta.migrate
32
- expect(subject.dump).to match_ruby expected_dsl
33
- }
34
- end
35
- end
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'Ridgepole::Client#diff -> migrate' do
4
- context 'when change virtual column / not null -> null' do
5
- let(:actual_dsl) do
6
- erbh(<<-ERB)
7
- create_table "books", force: :cascade do |t|
8
- t.string "title", null: false
9
- t.json "attrs", null: false
10
- t.index ["title"], name: "index_books_on_title"
11
- end
12
- ERB
13
- end
14
-
15
- let(:expected_dsl) do
16
- erbh(<<-ERB)
17
- create_table "books", force: :cascade do |t|
18
- t.string "title", null: false
19
- t.json "attrs"
20
- t.index ["title"], name: "index_books_on_title"
21
- end
22
- ERB
23
- end
24
-
25
- before { subject.diff(actual_dsl).migrate }
26
- subject { client }
27
-
28
- it {
29
- delta = subject.diff(expected_dsl)
30
- expect(delta.differ?).to be_truthy
31
- expect(subject.dump).to match_ruby actual_dsl
32
- delta.migrate
33
- expect(subject.dump).to match_ruby expected_dsl
34
- }
35
- end
36
-
37
- context 'when change virtual column / json -> string' do
38
- let(:actual_dsl) do
39
- erbh(<<-ERB)
40
- create_table "books", force: :cascade do |t|
41
- t.string "title", null: false
42
- t.json "attrs", null: false
43
- t.index ["title"], name: "index_books_on_title"
44
- end
45
- ERB
46
- end
47
-
48
- let(:expected_dsl) do
49
- erbh(<<-ERB)
50
- create_table "books", force: :cascade do |t|
51
- t.string "title", null: false
52
- t.string "attrs"
53
- t.index ["title"], name: "index_books_on_title"
54
- end
55
- ERB
56
- end
57
-
58
- before { subject.diff(actual_dsl).migrate }
59
- subject { client }
60
-
61
- it {
62
- delta = subject.diff(expected_dsl)
63
- expect(delta.differ?).to be_truthy
64
- expect(subject.dump).to match_ruby actual_dsl
65
- delta.migrate
66
- expect(subject.dump).to match_ruby expected_dsl
67
- }
68
- end
69
-
70
- context 'when change virtual column / string -> json' do
71
- let(:actual_dsl) do
72
- erbh(<<-ERB)
73
- create_table "books", force: :cascade do |t|
74
- t.string "title", null: false
75
- t.string "attrs"
76
- t.index ["title"], name: "index_books_on_title"
77
- end
78
- ERB
79
- end
80
-
81
- let(:expected_dsl) do
82
- erbh(<<-ERB)
83
- create_table "books", force: :cascade do |t|
84
- t.string "title", null: false
85
- t.json "attrs", null: false
86
- t.index ["title"], name: "index_books_on_title"
87
- end
88
- ERB
89
- end
90
-
91
- before { subject.diff(actual_dsl).migrate }
92
- subject { client }
93
-
94
- it {
95
- delta = subject.diff(expected_dsl)
96
- expect(delta.differ?).to be_truthy
97
- expect(subject.dump).to match_ruby actual_dsl
98
- delta.migrate
99
- expect(subject.dump).to match_ruby expected_dsl
100
- }
101
- end
102
- end