ridgepole 0.8.12 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +27 -20
  3. data/.rubocop.yml +5 -4
  4. data/.simplecov +6 -0
  5. data/Appraisals +4 -5
  6. data/README.md +22 -41
  7. data/bin/ridgepole +13 -3
  8. data/gemfiles/{activerecord_5.0.gemfile → activerecord_6.1.gemfile} +1 -2
  9. data/lib/ridgepole/client.rb +8 -3
  10. data/lib/ridgepole/default_limit.rb +1 -1
  11. data/lib/ridgepole/delta.rb +16 -1
  12. data/lib/ridgepole/diff.rb +50 -31
  13. data/lib/ridgepole/dsl_parser/table_definition.rb +49 -42
  14. data/lib/ridgepole/execute_expander.rb +10 -1
  15. data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +9 -1
  16. data/lib/ridgepole/external_sql_executer.rb +12 -1
  17. data/lib/ridgepole/version.rb +1 -1
  18. data/ridgepole.gemspec +6 -3
  19. data/spec/erb_helper.rb +1 -1
  20. data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +2 -2
  21. data/spec/mysql/bigint_pk/int_pk_spec.rb +1 -1
  22. data/spec/mysql/cli/ridgepole_spec.rb +35 -1
  23. data/spec/mysql/collation/collation_spec.rb +14 -14
  24. data/spec/mysql/comment/comment_spec.rb +9 -9
  25. data/spec/mysql/diff/diff2_spec.rb +5 -5
  26. data/spec/mysql/diff/diff_spec.rb +3 -3
  27. data/spec/mysql/dump/dump_class_method_spec.rb +13 -13
  28. data/spec/mysql/dump/dump_some_tables_spec.rb +4 -4
  29. data/spec/mysql/dump/dump_spec.rb +13 -13
  30. data/spec/mysql/dump/dump_unknown_column_type_spec.rb +2 -2
  31. data/spec/mysql/dump/dump_without_table_options_spec.rb +2 -2
  32. data/spec/mysql/fk/migrate_change_fk2_spec.rb +2 -2
  33. data/spec/mysql/fk/migrate_change_fk_spec.rb +88 -20
  34. data/spec/mysql/fk/migrate_create_fk_spec.rb +77 -22
  35. data/spec/mysql/fk/migrate_drop_fk_spec.rb +81 -26
  36. data/spec/mysql/fk/migrate_fk_with_column_spec.rb +16 -16
  37. data/spec/mysql/fk/migrate_ignore_fk_spec.rb +6 -6
  38. data/spec/mysql/migrate/migrate_add_column_order_spec.rb +2 -2
  39. data/spec/mysql/migrate/migrate_add_column_spec.rb +18 -18
  40. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +106 -18
  41. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +18 -18
  42. data/spec/mysql/migrate/migrate_change_column2_spec.rb +5 -5
  43. data/spec/mysql/migrate/migrate_change_column3_spec.rb +10 -10
  44. data/spec/mysql/migrate/migrate_change_column5_spec.rb +3 -3
  45. data/spec/mysql/migrate/migrate_change_column6_spec.rb +7 -7
  46. data/spec/mysql/migrate/migrate_change_column8_spec.rb +38 -5
  47. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +2 -14
  48. data/spec/mysql/migrate/migrate_change_column_spec.rb +21 -21
  49. data/spec/mysql/migrate/migrate_change_index2_spec.rb +5 -5
  50. data/spec/mysql/migrate/migrate_change_index3_spec.rb +7 -7
  51. data/spec/mysql/migrate/migrate_change_index4_spec.rb +6 -6
  52. data/spec/mysql/migrate/migrate_change_index5_spec.rb +4 -4
  53. data/spec/mysql/migrate/migrate_change_index6_spec.rb +27 -27
  54. data/spec/mysql/migrate/migrate_change_index7_spec.rb +4 -4
  55. data/spec/mysql/migrate/migrate_change_index8_spec.rb +4 -4
  56. data/spec/mysql/migrate/migrate_change_index_spec.rb +34 -28
  57. data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +5 -5
  58. data/spec/mysql/migrate/migrate_create_index2_spec.rb +24 -24
  59. data/spec/mysql/migrate/migrate_create_index_spec.rb +18 -18
  60. data/spec/mysql/migrate/migrate_create_table_spec.rb +16 -16
  61. data/spec/mysql/migrate/migrate_create_table_with_ignore_spec.rb +4 -4
  62. data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +4 -4
  63. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +16 -16
  64. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +18 -18
  65. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +16 -16
  66. data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +1 -1
  67. data/spec/mysql/migrate/migrate_drop_column_spec.rb +18 -18
  68. data/spec/mysql/migrate/migrate_drop_index_spec.rb +15 -15
  69. data/spec/mysql/migrate/migrate_drop_table_spec.rb +16 -16
  70. data/spec/mysql/migrate/migrate_empty_spec.rb +9 -9
  71. data/spec/mysql/migrate/migrate_execute_spec.rb +32 -32
  72. data/spec/mysql/migrate/migrate_ignore_column_spec.rb +4 -4
  73. data/spec/mysql/migrate/migrate_ignore_index_spec.rb +5 -5
  74. data/spec/mysql/migrate/migrate_log_file_spec.rb +16 -16
  75. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +18 -18
  76. data/spec/mysql/migrate/migrate_noop_spec.rb +12 -12
  77. data/spec/mysql/migrate/migrate_primary_key_spec.rb +31 -6
  78. data/spec/mysql/migrate/migrate_rename_column_spec.rb +18 -18
  79. data/spec/mysql/migrate/migrate_rename_table_spec.rb +22 -22
  80. data/spec/mysql/migrate/migrate_same_spec.rb +13 -13
  81. data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +2 -2
  82. data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +18 -18
  83. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +18 -18
  84. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +18 -18
  85. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +18 -18
  86. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +2 -2
  87. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +6 -6
  88. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +9 -9
  89. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +8 -8
  90. data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +5 -5
  91. data/spec/mysql57/json/add_json_column_spec.rb +2 -2
  92. data/spec/mysql57/json/change_json_column_spec.rb +6 -6
  93. data/spec/mysql57/json/drop_json_column_spec.rb +2 -2
  94. data/spec/mysql57/virtual/add_virtual_column_spec.rb +1 -1
  95. data/spec/mysql57/virtual/change_virtual_column_spec.rb +1 -1
  96. data/spec/mysql57/virtual/drop_virtual_column_spec.rb +1 -1
  97. data/spec/postgresql/dump/dump_spec.rb +13 -13
  98. data/spec/postgresql/fk/migrate_change_fk_spec.rb +6 -6
  99. data/spec/postgresql/fk/migrate_create_fk_spec.rb +5 -5
  100. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +8 -8
  101. data/spec/postgresql/migrate/migrate_add_column_spec.rb +27 -20
  102. data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +1 -1
  103. data/spec/postgresql/migrate/migrate_change_column_spec.rb +20 -16
  104. data/spec/postgresql/migrate/migrate_change_index_spec.rb +18 -18
  105. data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +1 -1
  106. data/spec/postgresql/migrate/migrate_create_table_spec.rb +14 -14
  107. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +29 -22
  108. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +17 -17
  109. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +3 -3
  110. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +15 -15
  111. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +16 -16
  112. data/spec/postgresql/migrate/migrate_primary_key2_spec.rb +1 -1
  113. data/spec/postgresql/migrate/migrate_primary_key_spec.rb +1 -1
  114. data/spec/postgresql/migrate/migrate_references_spec.rb +6 -6
  115. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +18 -18
  116. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +20 -20
  117. data/spec/postgresql/migrate/migrate_same_spec.rb +13 -13
  118. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +3 -3
  119. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +4 -4
  120. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +4 -4
  121. data/spec/processing_for_ci.rb +13 -0
  122. data/spec/spec_const.rb +1 -1
  123. data/spec/spec_helper.rb +2 -1
  124. metadata +68 -43
  125. data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +0 -31
  126. data/omnibus-ridgepole/.gitignore +0 -10
  127. data/omnibus-ridgepole/Dockerfile.centos +0 -25
  128. data/omnibus-ridgepole/Dockerfile.ubuntu +0 -21
  129. data/omnibus-ridgepole/Gemfile +0 -24
  130. data/omnibus-ridgepole/README.md +0 -15
  131. data/omnibus-ridgepole/Rakefile +0 -38
  132. data/omnibus-ridgepole/config/projects/ridgepole.rb +0 -27
  133. data/omnibus-ridgepole/config/software/ridgepole.rb +0 -13
  134. data/omnibus-ridgepole/omnibus.rb +0 -54
  135. data/omnibus-ridgepole/package-scripts/ridgepole/postinst +0 -1
  136. data/omnibus-ridgepole/package-scripts/ridgepole/postrm +0 -1
  137. data/spec/mysql/bigint_pk/bigint_pk_spec.rb +0 -47
  138. data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +0 -141
  139. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +0 -141
  140. data/spec/processing_for_travis.rb +0 -11
@@ -174,12 +174,12 @@ describe 'Ridgepole::Client.diff' do
174
174
  it {
175
175
  delta = subject.diff(actual_dsl, expected_dsl)
176
176
  expect(delta.differ?).to be_truthy
177
- expect(delta.script).to match_ruby erbh(<<-ERB)
178
- change_column("employee_clubs", "club_id", :integer, **<%= {:unsigned=>false, :null=>true, :default=>nil} + cond('>= 5.1', comment: nil) %>)
177
+ expect(delta.script).to match_ruby(<<-RUBY)
178
+ change_column("employee_clubs", "club_id", :integer, **{:unsigned=>false, :null=>true, :default=>nil, :comment=>nil})
179
179
 
180
- change_column("employees", "last_name", :string, **<%= {:limit=>20, :default=>"XXX", :unsigned=>false} + cond('>= 5.1', comment: nil) %>)
181
- change_column("employees", "gender", :string, **<%= {:limit=>2, :null=>false, :default=>nil, :unsigned=>false} + cond('>= 5.1', comment: nil) %>)
182
- ERB
180
+ change_column("employees", "last_name", :string, **{:limit=>20, :default=>"XXX", :unsigned=>false, :comment=>nil})
181
+ change_column("employees", "gender", :string, **{:limit=>2, :null=>false, :default=>nil, :unsigned=>false, :comment=>nil})
182
+ RUBY
183
183
  }
184
184
 
185
185
  after do
@@ -149,10 +149,10 @@ describe 'Ridgepole::Client.diff' do
149
149
  delta = subject.diff(actual_dsl, expected_dsl)
150
150
  expect(delta.differ?).to be_truthy
151
151
  expect(delta.script).to match_ruby erbh(<<-ERB)
152
- change_column("employee_clubs", "club_id", :integer, **<%= {:unsigned=>false, :null=>true, :default=>nil} + cond('>= 5.1', comment: nil) %>)
152
+ change_column("employee_clubs", "club_id", :integer, **{:unsigned=>false, :null=>true, :default=>nil, :comment=>nil})
153
153
 
154
- change_column("employees", "last_name", :string, **<%= {:limit=>20, :default=>"XXX", :unsigned=>false} + cond('>= 5.1', comment: nil) %>)
155
- change_column("employees", "gender", :string, **<%= {:limit=>2, :null=>false, :default=>nil, :unsigned=>false} + cond('>= 5.1', comment: nil) %>)
154
+ change_column("employees", "last_name", :string, **{:limit=>20, :default=>"XXX", :unsigned=>false, :comment=>nil})
155
+ change_column("employees", "gender", :string, **{:limit=>2, :null=>false, :default=>nil, :unsigned=>false, :comment=>nil})
156
156
  ERB
157
157
  }
158
158
  end
@@ -7,14 +7,14 @@ describe 'Ridgepole::Client.dump' do
7
7
 
8
8
  it {
9
9
  expect(subject.dump(conn_spec, dump_without_table_options: true)).to match_fuzzy erbh(<<-ERB)
10
- create_table "clubs", <%= i cond('>= 5.1', id: :integer) %>, unsigned: true, force: :cascade do |t|
10
+ create_table "clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
11
11
  t.string "name", default: "", null: false
12
- t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
12
+ t.index ["name"], name: "idx_name", unique: true
13
13
  end
14
14
 
15
- create_table "departments", primary_key: "dept_no", id: :string, limit: 4, force: :cascade do |t|
15
+ create_table "departments", primary_key: "dept_no", <%= i cond(">= 6.1", { id: { type: :string, limit: 4 } }, { id: :string, limit: 4 }) %>, force: :cascade do |t|
16
16
  t.string "dept_name", limit: 40, null: false
17
- t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
17
+ t.index ["dept_name"], name: "dept_name", unique: true
18
18
  end
19
19
 
20
20
  create_table "dept_emp", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
@@ -22,8 +22,8 @@ describe 'Ridgepole::Client.dump' do
22
22
  t.string "dept_no", limit: 4, null: false
23
23
  t.date "from_date", null: false
24
24
  t.date "to_date", null: false
25
- t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
26
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
25
+ t.index ["dept_no"], name: "dept_no"
26
+ t.index ["emp_no"], name: "emp_no"
27
27
  end
28
28
 
29
29
  create_table "dept_manager", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
@@ -31,17 +31,17 @@ describe 'Ridgepole::Client.dump' do
31
31
  t.integer "emp_no", null: false
32
32
  t.date "from_date", null: false
33
33
  t.date "to_date", null: false
34
- t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
35
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
34
+ t.index ["dept_no"], name: "dept_no"
35
+ t.index ["emp_no"], name: "emp_no"
36
36
  end
37
37
 
38
- create_table "employee_clubs", <%= i cond('>= 5.1', id: :integer) %>, unsigned: true, force: :cascade do |t|
38
+ create_table "employee_clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true }}) %>, force: :cascade do |t|
39
39
  t.integer "emp_no", null: false, unsigned: true
40
40
  t.integer "club_id", null: false, unsigned: true
41
- t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id", <%= i cond(5.0, using: :btree) %>
41
+ t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
42
42
  end
43
43
 
44
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('>= 5.1', default: nil) %>, force: :cascade do |t|
44
+ create_table "employees", primary_key: "emp_no", id: :integer, default: nil, force: :cascade do |t|
45
45
  t.date "birth_date", null: false
46
46
  t.string "first_name", limit: 14, null: false
47
47
  t.string "last_name", limit: 16, null: false
@@ -58,7 +58,7 @@ describe 'Ridgepole::Client.dump' do
58
58
  t.integer "salary", null: false
59
59
  t.date "from_date", null: false
60
60
  t.date "to_date", null: false
61
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
61
+ t.index ["emp_no"], name: "emp_no"
62
62
  end
63
63
 
64
64
  create_table "titles", primary_key: ["emp_no", "title", "from_date"], force: :cascade do |t|
@@ -66,7 +66,7 @@ describe 'Ridgepole::Client.dump' do
66
66
  t.string "title", limit: 50, null: false
67
67
  t.date "from_date", null: false
68
68
  t.date "to_date"
69
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
69
+ t.index ["emp_no"], name: "emp_no"
70
70
  end
71
71
  ERB
72
72
  }
@@ -7,7 +7,7 @@ describe 'Ridgepole::Client#dump' do
7
7
 
8
8
  it {
9
9
  expect(subject.dump).to match_fuzzy erbh(<<-ERB)
10
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('>= 5.1', default: nil) %>, force: :cascade do |t|
10
+ create_table "employees", primary_key: "emp_no", id: :integer, default: nil, force: :cascade do |t|
11
11
  t.date "birth_date", null: false
12
12
  t.string "first_name", limit: 14, null: false
13
13
  t.string "last_name", limit: 16, null: false
@@ -24,7 +24,7 @@ describe 'Ridgepole::Client#dump' do
24
24
  t.integer "salary", null: false
25
25
  t.date "from_date", null: false
26
26
  t.date "to_date", null: false
27
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
27
+ t.index ["emp_no"], name: "emp_no"
28
28
  end
29
29
  ERB
30
30
  }
@@ -45,7 +45,7 @@ describe 'Ridgepole::Client#dump' do
45
45
 
46
46
  it {
47
47
  expect(subject.dump).to match_fuzzy erbh(<<-ERB)
48
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('>= 5.1', default: nil) %>, force: :cascade do |t|
48
+ create_table "employees", primary_key: "emp_no", id: :integer, default: nil, force: :cascade do |t|
49
49
  t.date "birth_date", null: false
50
50
  t.string "first_name", limit: 14, null: false
51
51
  t.string "last_name", limit: 16, null: false
@@ -62,7 +62,7 @@ describe 'Ridgepole::Client#dump' do
62
62
  t.integer "salary", null: false
63
63
  t.date "from_date", null: false
64
64
  t.date "to_date", null: false
65
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
65
+ t.index ["emp_no"], name: "emp_no"
66
66
  end
67
67
  ERB
68
68
  }
@@ -7,14 +7,14 @@ describe 'Ridgepole::Client#dump' do
7
7
 
8
8
  it {
9
9
  expect(subject.dump).to match_fuzzy erbh(<<-ERB)
10
- create_table "clubs", <%= i cond('>= 5.1',id: :integer) %>, unsigned: true, force: :cascade do |t|
10
+ create_table "clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
11
11
  t.string "name", default: "", null: false
12
- t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
12
+ t.index ["name"], name: "idx_name", unique: true
13
13
  end
14
14
 
15
- create_table "departments", primary_key: "dept_no", id: :string, limit: 4, force: :cascade do |t|
15
+ create_table "departments", primary_key: "dept_no", <%= i cond(">= 6.1", { id: { type: :string, limit: 4 } }, { id: :string, limit: 4 }) %>, force: :cascade do |t|
16
16
  t.string "dept_name", limit: 40, null: false
17
- t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
17
+ t.index ["dept_name"], name: "dept_name", unique: true
18
18
  end
19
19
 
20
20
  create_table "dept_emp", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
@@ -22,8 +22,8 @@ describe 'Ridgepole::Client#dump' do
22
22
  t.string "dept_no", limit: 4, null: false
23
23
  t.date "from_date", null: false
24
24
  t.date "to_date", null: false
25
- t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
26
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
25
+ t.index ["dept_no"], name: "dept_no"
26
+ t.index ["emp_no"], name: "emp_no"
27
27
  end
28
28
 
29
29
  create_table "dept_manager", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
@@ -31,17 +31,17 @@ describe 'Ridgepole::Client#dump' do
31
31
  t.integer "emp_no", null: false
32
32
  t.date "from_date", null: false
33
33
  t.date "to_date", null: false
34
- t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
35
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
34
+ t.index ["dept_no"], name: "dept_no"
35
+ t.index ["emp_no"], name: "emp_no"
36
36
  end
37
37
 
38
- create_table "employee_clubs", <%= i cond('>= 5.1',id: :integer) %>, unsigned: true, force: :cascade do |t|
38
+ create_table "employee_clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
39
39
  t.integer "emp_no", null: false, unsigned: true
40
40
  t.integer "club_id", null: false, unsigned: true
41
- t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id", <%= i cond(5.0, using: :btree) %>
41
+ t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id"
42
42
  end
43
43
 
44
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('>= 5.1',default: nil) %>, force: :cascade do |t|
44
+ create_table "employees", primary_key: "emp_no", id: :integer, default: nil, force: :cascade do |t|
45
45
  t.date "birth_date", null: false
46
46
  t.string "first_name", limit: 14, null: false
47
47
  t.string "last_name", limit: 16, null: false
@@ -58,7 +58,7 @@ describe 'Ridgepole::Client#dump' do
58
58
  t.integer "salary", null: false
59
59
  t.date "from_date", null: false
60
60
  t.date "to_date", null: false
61
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
61
+ t.index ["emp_no"], name: "emp_no"
62
62
  end
63
63
 
64
64
  create_table "titles", primary_key: ["emp_no", "title", "from_date"], force: :cascade do |t|
@@ -66,7 +66,7 @@ describe 'Ridgepole::Client#dump' do
66
66
  t.string "title", limit: 50, null: false
67
67
  t.date "from_date", null: false
68
68
  t.date "to_date"
69
- t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
69
+ t.index ["emp_no"], name: "emp_no"
70
70
  end
71
71
  ERB
72
72
  }
@@ -7,9 +7,9 @@ describe 'Ridgepole::Client#dump' do
7
7
 
8
8
  it {
9
9
  expect(subject.dump).to match_fuzzy erbh(<<-ERB)
10
- create_table "clubs", <%= i cond('>= 5.1',id: :integer) %>, unsigned: true, force: :cascade do |t|
10
+ create_table "clubs", <%= i cond('< 6.1', { id: :integer, unsigned: true }, { id: { type: :integer, unsigned: true } }) %>, force: :cascade do |t|
11
11
  t.string "name", default: "", null: false
12
- t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
12
+ t.index ["name"], name: "idx_name", unique: true
13
13
  end
14
14
  ERB
15
15
  }
@@ -3,7 +3,7 @@
3
3
  describe 'Ridgepole::Client#dump' do
4
4
  let(:actual_dsl) do
5
5
  erbh(<<-'ERB')
6
- create_table "books", unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='\"london\" bridge \"is\" falling \"down\"'" do |t|
6
+ create_table "books", unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='\"london\" bridge \"is\" falling \"down\"'" do |t|
7
7
  t.string "title", null: false
8
8
  t.integer "author_id", null: false
9
9
  t.datetime "created_at"
@@ -15,7 +15,7 @@ describe 'Ridgepole::Client#dump' do
15
15
  context 'when without table options' do
16
16
  let(:expected_dsl) do
17
17
  erbh(<<-ERB)
18
- create_table "books", <%= i cond('>= 5.1',id: :bigint) %>, unsigned: true, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
18
+ create_table "books", <%= i cond('>= 6.1', { id: { type: :bigint, unsigned: true } }, { id: :bigint, unsigned: true }) %>, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
19
19
  t.string "title", null: false
20
20
  t.integer "author_id", null: false
21
21
  t.datetime "created_at"
@@ -22,12 +22,12 @@ describe 'Ridgepole::Client#diff -> migrate' do
22
22
  erbh(<<-ERB)
23
23
  create_table "lessons", force: :cascade do |t|
24
24
  t.bigint "user_id2", null: false
25
- t.index ["user_id2"], name: "index_lessons_on_user_id2", <%= i cond(5.0, using: :btree) %>
25
+ t.index ["user_id2"], name: "index_lessons_on_user_id2"
26
26
  end
27
27
 
28
28
  create_table "users", id: false, force: :cascade do |t|
29
29
  t.bigint "my_original_id", null: false
30
- t.index ["my_original_id"], name: "index_users_on_my_original_id", unique: true, <%= i cond(5.0, using: :btree) %>
30
+ t.index ["my_original_id"], name: "index_users_on_my_original_id", unique: true
31
31
  end
32
32
 
33
33
  add_foreign_key "lessons", "users", primary_key: "my_original_id", column: "user_id2"
@@ -4,12 +4,12 @@ describe 'Ridgepole::Client#diff -> migrate' do
4
4
  context 'when change fk' do
5
5
  let(:actual_dsl) do
6
6
  erbh(<<-ERB)
7
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
7
+ create_table "parent", id: :integer, force: :cascade do |t|
8
8
  end
9
9
 
10
10
  create_table "child", force: :cascade do |t|
11
11
  t.integer "parent_id"
12
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
12
+ t.index ["parent_id"], name: "par_id"
13
13
  end
14
14
 
15
15
  add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
@@ -20,10 +20,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
20
20
  erbh(<<-ERB)
21
21
  create_table "child", force: :cascade do |t|
22
22
  t.integer "parent_id"
23
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
23
+ t.index ["parent_id"], name: "par_id"
24
24
  end
25
25
 
26
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
26
+ create_table "parent", id: :integer, force: :cascade do |t|
27
27
  end
28
28
 
29
29
  add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
@@ -34,10 +34,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
34
34
  erbh(<<-ERB)
35
35
  create_table "child", force: :cascade do |t|
36
36
  t.integer "parent_id"
37
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
37
+ t.index ["parent_id"], name: "par_id"
38
38
  end
39
39
 
40
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
40
+ create_table "parent", id: :integer, force: :cascade do |t|
41
41
  end
42
42
 
43
43
  add_foreign_key "child", "parent", name: "child_ibfk_1"
@@ -57,15 +57,83 @@ describe 'Ridgepole::Client#diff -> migrate' do
57
57
  }
58
58
  end
59
59
 
60
+ context 'when change fk using `t.foreign_key`' do
61
+ let(:actual_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
+ t.foreign_key "parent", name: "child_ibfk_1", on_delete: :cascade
70
+ end
71
+ ERB
72
+ end
73
+
74
+ let(:sorted_actual_dsl) do
75
+ erbh(<<-ERB)
76
+ create_table "child", force: :cascade do |t|
77
+ t.integer "parent_id"
78
+ t.index ["parent_id"], name: "par_id"
79
+ end
80
+
81
+ create_table "parent", id: :integer, force: :cascade do |t|
82
+ end
83
+
84
+ add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
85
+ ERB
86
+ end
87
+
88
+ let(:expected_dsl) do
89
+ erbh(<<-ERB)
90
+ create_table "child", force: :cascade do |t|
91
+ t.integer "parent_id"
92
+ t.index ["parent_id"], name: "par_id"
93
+ end
94
+
95
+ create_table "parent", id: :integer, force: :cascade do |t|
96
+ end
97
+
98
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
99
+ ERB
100
+ end
101
+
102
+ let(:expected_dsl_using_t_foreign_key) do
103
+ erbh(<<-ERB)
104
+ create_table "child", force: :cascade do |t|
105
+ t.integer "parent_id"
106
+ t.index ["parent_id"], name: "par_id"
107
+ t.foreign_key "parent", name: "child_ibfk_1"
108
+ end
109
+
110
+ create_table "parent", id: :integer, force: :cascade do |t|
111
+ end
112
+ ERB
113
+ end
114
+
115
+ before { subject.diff(actual_dsl).migrate }
116
+
117
+ subject { client }
118
+
119
+ it {
120
+ delta = subject.diff(expected_dsl_using_t_foreign_key)
121
+ expect(delta.differ?).to be_truthy
122
+ expect(subject.dump).to match_fuzzy sorted_actual_dsl
123
+ delta.migrate
124
+ expect(subject.dump).to match_ruby expected_dsl
125
+ }
126
+ end
127
+
60
128
  context 'when change fk without name' do
61
129
  let(:actual_dsl) do
62
130
  erbh(<<-ERB)
63
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
131
+ create_table "parent", id: :integer, force: :cascade do |t|
64
132
  end
65
133
 
66
134
  create_table "child", force: :cascade do |t|
67
135
  t.integer "parent_id"
68
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
136
+ t.index ["parent_id"], name: "par_id"
69
137
  end
70
138
 
71
139
  add_foreign_key "child", "parent", on_delete: :cascade
@@ -76,10 +144,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
76
144
  erbh(<<-ERB)
77
145
  create_table "child", force: :cascade do |t|
78
146
  t.integer "parent_id"
79
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
147
+ t.index ["parent_id"], name: "par_id"
80
148
  end
81
149
 
82
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
150
+ create_table "parent", id: :integer, force: :cascade do |t|
83
151
  end
84
152
 
85
153
  add_foreign_key "child", "parent", on_delete: :cascade
@@ -90,10 +158,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
90
158
  erbh(<<-ERB)
91
159
  create_table "child", force: :cascade do |t|
92
160
  t.integer "parent_id"
93
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
161
+ t.index ["parent_id"], name: "par_id"
94
162
  end
95
163
 
96
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
164
+ create_table "parent", id: :integer, force: :cascade do |t|
97
165
  end
98
166
 
99
167
  add_foreign_key "child", "parent"
@@ -118,10 +186,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
118
186
  erbh(<<-ERB)
119
187
  create_table "child", force: :cascade do |t|
120
188
  t.integer "parent_id"
121
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
189
+ t.index ["parent_id"], name: "par_id"
122
190
  end
123
191
 
124
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
192
+ create_table "parent", id: :integer, force: :cascade do |t|
125
193
  end
126
194
 
127
195
  add_foreign_key "child", "parent", name: "child_ibfk_1"
@@ -132,10 +200,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
132
200
  erbh(<<-ERB)
133
201
  create_table "child", force: :cascade do |t|
134
202
  t.integer "parent2_id"
135
- t.index ["parent2_id"], name: "par2_id", <%= i cond(5.0, using: :btree) %>
203
+ t.index ["parent2_id"], name: "par2_id"
136
204
  end
137
205
 
138
- create_table "parent2", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
206
+ create_table "parent2", id: :integer, force: :cascade do |t|
139
207
  end
140
208
 
141
209
  add_foreign_key "child", "parent2", name: "child_ibfk_2"
@@ -159,10 +227,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
159
227
  erbh(<<-ERB)
160
228
  create_table "child", force: :cascade do |t|
161
229
  t.integer "parent_id"
162
- t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
230
+ t.index ["parent_id"], name: "par_id"
163
231
  end
164
232
 
165
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
233
+ create_table "parent", id: :integer, force: :cascade do |t|
166
234
  end
167
235
 
168
236
  add_foreign_key "child", "parent"
@@ -173,10 +241,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
173
241
  erbh(<<-ERB)
174
242
  create_table "child", force: :cascade do |t|
175
243
  t.integer "parent2_id"
176
- t.index ["parent2_id"], name: "par2_id", <%= i cond(5.0, using: :btree) %>
244
+ t.index ["parent2_id"], name: "par2_id"
177
245
  end
178
246
 
179
- create_table "parent2", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade do |t|
247
+ create_table "parent2", id: :integer, force: :cascade do |t|
180
248
  end
181
249
 
182
250
  add_foreign_key "child", "parent2"