ridgepole 0.7.0.alpha → 0.7.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +1 -0
  4. data/README.md +7 -5
  5. data/bin/ridgepole +14 -14
  6. data/lib/ridgepole/cli/config.rb +1 -1
  7. data/lib/ridgepole/client.rb +0 -4
  8. data/lib/ridgepole/delta.rb +15 -9
  9. data/lib/ridgepole/diff.rb +13 -9
  10. data/lib/ridgepole/dsl_parser/context.rb +2 -6
  11. data/lib/ridgepole/version.rb +1 -1
  12. data/ridgepole.gemspec +3 -1
  13. data/spec/erb_helper.rb +0 -39
  14. data/spec/hide_pending_formatter.rb +6 -0
  15. data/spec/mysql/bigint_pk/bigint_pk_spec.rb +9 -9
  16. data/spec/mysql/bigint_pk/int_pk_spec.rb +9 -9
  17. data/spec/mysql/cli/ridgepole_spec.rb +2 -2
  18. data/spec/mysql/collation/collation_spec.rb +28 -28
  19. data/spec/mysql/comment/comment_spec.rb +36 -36
  20. data/spec/mysql/default_lambda/default_lambda_spec.rb +1 -1
  21. data/spec/mysql/diff/diff2_spec.rb +41 -41
  22. data/spec/mysql/diff/diff_spec.rb +41 -41
  23. data/spec/mysql/dump/dump_class_method_spec.rb +26 -33
  24. data/spec/mysql/dump/dump_some_tables_spec.rb +16 -18
  25. data/spec/mysql/dump/dump_spec.rb +27 -34
  26. data/spec/mysql/dump/dump_without_table_options_spec.rb +5 -5
  27. data/spec/mysql/fk/migrate_change_fk_spec.rb +76 -23
  28. data/spec/mysql/fk/migrate_create_fk_spec.rb +70 -50
  29. data/spec/mysql/fk/migrate_drop_fk_spec.rb +131 -32
  30. data/spec/mysql/migrate/check_orphan_index_spec.rb +19 -19
  31. data/spec/mysql/migrate/migrate_add_column2_spec.rb +33 -45
  32. data/spec/mysql/migrate/migrate_add_column_order_spec.rb +47 -47
  33. data/spec/mysql/migrate/migrate_add_column_spec.rb +75 -89
  34. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +72 -86
  35. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +72 -86
  36. data/spec/mysql/migrate/migrate_change_column2_spec.rb +27 -32
  37. data/spec/mysql/migrate/migrate_change_column3_spec.rb +78 -78
  38. data/spec/mysql/migrate/migrate_change_column4_spec.rb +24 -24
  39. data/spec/mysql/migrate/migrate_change_column5_spec.rb +42 -42
  40. data/spec/mysql/migrate/migrate_change_column6_spec.rb +60 -60
  41. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +47 -47
  42. data/spec/mysql/migrate/migrate_change_column_float_spec.rb +16 -16
  43. data/spec/mysql/migrate/migrate_change_column_spec.rb +65 -79
  44. data/spec/mysql/migrate/migrate_change_index2_spec.rb +22 -27
  45. data/spec/mysql/migrate/migrate_change_index3_spec.rb +52 -62
  46. data/spec/mysql/migrate/migrate_change_index4_spec.rb +32 -38
  47. data/spec/mysql/migrate/migrate_change_index5_spec.rb +24 -28
  48. data/spec/mysql/migrate/migrate_change_index6_spec.rb +105 -119
  49. data/spec/mysql/migrate/migrate_change_index7_spec.rb +27 -30
  50. data/spec/mysql/migrate/migrate_change_index_spec.rb +99 -120
  51. data/spec/mysql/migrate/migrate_change_table_option_spec.rb +14 -14
  52. data/spec/mysql/migrate/migrate_create_index2_spec.rb +101 -112
  53. data/spec/mysql/migrate/migrate_create_index_spec.rb +55 -66
  54. data/spec/mysql/migrate/migrate_create_table_spec.rb +68 -91
  55. data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +1 -1
  56. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +58 -70
  57. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +62 -76
  58. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +58 -72
  59. data/spec/mysql/migrate/migrate_drop_column_spec.rb +63 -77
  60. data/spec/mysql/migrate/migrate_drop_index_spec.rb +55 -66
  61. data/spec/mysql/migrate/migrate_drop_table_spec.rb +51 -63
  62. data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +3 -3
  63. data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +12 -12
  64. data/spec/mysql/migrate/migrate_empty_spec.rb +35 -42
  65. data/spec/mysql/migrate/migrate_execute_spec.rb +16 -24
  66. data/spec/mysql/migrate/migrate_log_file_spec.rb +58 -70
  67. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +75 -99
  68. data/spec/mysql/migrate/migrate_noop_spec.rb +38 -38
  69. data/spec/mysql/migrate/migrate_rename_column_spec.rb +74 -88
  70. data/spec/mysql/migrate/migrate_rename_table_spec.rb +100 -97
  71. data/spec/mysql/migrate/migrate_same_default_null_spec.rb +18 -18
  72. data/spec/mysql/migrate/migrate_same_spec.rb +29 -37
  73. data/spec/mysql/migrate/migrate_script_error_spec.rb +19 -19
  74. data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +148 -0
  75. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +70 -84
  76. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +70 -84
  77. data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +87 -87
  78. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +61 -75
  79. data/spec/mysql/migrate/migrate_with_tables_spec.rb +41 -41
  80. data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +10 -10
  81. data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +67 -78
  82. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +67 -78
  83. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +9 -9
  84. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +21 -24
  85. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +35 -67
  86. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +28 -34
  87. data/spec/postgresql/diff/diff_spec.rb +37 -37
  88. data/spec/postgresql/dump/dump_spec.rb +27 -34
  89. data/spec/postgresql/fk/migrate_change_fk_spec.rb +76 -23
  90. data/spec/postgresql/fk/migrate_create_fk_spec.rb +73 -54
  91. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +131 -32
  92. data/spec/postgresql/migrate/migrate_add_column_spec.rb +63 -75
  93. data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +1 -1
  94. data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +7 -7
  95. data/spec/postgresql/migrate/migrate_change_column_spec.rb +53 -65
  96. data/spec/postgresql/migrate/migrate_change_index_spec.rb +54 -68
  97. data/spec/postgresql/migrate/migrate_create_table_spec.rb +56 -77
  98. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +46 -60
  99. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +41 -55
  100. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +3 -3
  101. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +51 -62
  102. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +48 -60
  103. data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +6 -6
  104. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +54 -68
  105. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +62 -78
  106. data/spec/postgresql/migrate/migrate_same_spec.rb +27 -34
  107. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +21 -24
  108. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +35 -66
  109. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +28 -34
  110. data/spec/spec_helper.rb +1 -1
  111. metadata +9 -8
  112. data/ridgepole.iml +0 -9
  113. data/spec/string_ext.rb +0 -40
@@ -5,70 +5,63 @@ describe 'Ridgepole::Client.dump' do
5
5
 
6
6
  it {
7
7
  expect(subject.dump(conn_spec, dump_without_table_options: true)).to match_fuzzy erbh(<<-EOS)
8
- create_table "clubs", <%= i cond('5.1.', id: :integer) %>, unsigned: true, force: :cascade do |t|
8
+ create_table "clubs", <%= i cond(5.1, id: :integer) %>, unsigned: true, force: :cascade do |t|
9
9
  t.string "name", default: "", null: false
10
+ t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
10
11
  end
11
12
 
12
- <%= add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree %>
13
-
14
13
  create_table "departments", primary_key: "dept_no", id: :string, limit: 4, force: :cascade do |t|
15
14
  t.string "dept_name", limit: 40, null: false
15
+ t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
16
16
  end
17
17
 
18
- <%= add_index "departments", ["dept_name"], {name: "dept_name", unique: true} + cond('5.0', using: :btree) %>
19
-
20
18
  create_table "dept_emp", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
21
19
  t.integer "emp_no", null: false
22
- t.string "dept_no", limit: 4, null: false
23
- t.date "from_date", null: false
24
- t.date "to_date", null: false
20
+ t.string "dept_no", limit: 4, null: false
21
+ t.date "from_date", null: false
22
+ t.date "to_date", null: false
23
+ t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
24
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
25
25
  end
26
26
 
27
- <%= add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree %>
28
- <%= add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree %>
29
-
30
27
  create_table "dept_manager", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
31
- t.string "dept_no", limit: 4, null: false
28
+ t.string "dept_no", limit: 4, null: false
32
29
  t.integer "emp_no", null: false
33
- t.date "from_date", null: false
34
- t.date "to_date", null: false
30
+ t.date "from_date", null: false
31
+ t.date "to_date", null: false
32
+ t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
33
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
35
34
  end
36
35
 
37
- <%= add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree %>
38
- <%= add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree %>
39
-
40
- create_table "employee_clubs", <%= i cond('5.1.', id: :integer) %>, unsigned: true, force: :cascade do |t|
36
+ create_table "employee_clubs", <%= i cond(5.1, id: :integer) %>, unsigned: true, force: :cascade do |t|
41
37
  t.integer "emp_no", null: false, unsigned: true
42
38
  t.integer "club_id", null: false, unsigned: true
39
+ t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id", <%= i cond(5.0, using: :btree) %>
43
40
  end
44
41
 
45
- <%= add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree %>
46
-
47
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('5.1.', default: nil) %>, force: :cascade do |t|
48
- t.date "birth_date", null: false
42
+ create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond(5.1, default: nil) %>, force: :cascade do |t|
43
+ t.date "birth_date", null: false
49
44
  t.string "first_name", limit: 14, null: false
50
- t.string "last_name", limit: 16, null: false
51
- t.string "gender", limit: 1, null: false
52
- t.date "hire_date", null: false
45
+ t.string "last_name", limit: 16, null: false
46
+ t.string "gender", limit: 1, null: false
47
+ t.date "hire_date", null: false
53
48
  end
54
49
 
55
50
  create_table "salaries", primary_key: ["emp_no", "from_date"], force: :cascade do |t|
56
51
  t.integer "emp_no", null: false
57
52
  t.integer "salary", null: false
58
- t.date "from_date", null: false
59
- t.date "to_date", null: false
53
+ t.date "from_date", null: false
54
+ t.date "to_date", null: false
55
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
60
56
  end
61
57
 
62
- <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
63
-
64
58
  create_table "titles", primary_key: ["emp_no", "title", "from_date"], force: :cascade do |t|
65
59
  t.integer "emp_no", null: false
66
- t.string "title", limit: 50, null: false
67
- t.date "from_date", null: false
60
+ t.string "title", limit: 50, null: false
61
+ t.date "from_date", null: false
68
62
  t.date "to_date"
63
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
69
64
  end
70
-
71
- <%= add_index "titles", ["emp_no"], name: "emp_no", using: :btree %>
72
65
  EOS
73
66
  }
74
67
  end
@@ -5,22 +5,21 @@ describe 'Ridgepole::Client#dump' do
5
5
 
6
6
  it {
7
7
  expect(subject.dump).to match_fuzzy erbh(<<-EOS)
8
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('5.1', default: nil) %>, force: :cascade do |t|
9
- t.date "birth_date", null: false
8
+ create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond(5.1, default: nil) %>, force: :cascade do |t|
9
+ t.date "birth_date", null: false
10
10
  t.string "first_name", limit: 14, null: false
11
- t.string "last_name", limit: 16, null: false
12
- t.string "gender", limit: 1, null: false
13
- t.date "hire_date", null: false
11
+ t.string "last_name", limit: 16, null: false
12
+ t.string "gender", limit: 1, null: false
13
+ t.date "hire_date", null: false
14
14
  end
15
15
 
16
16
  create_table "salaries", primary_key: ["emp_no", "from_date"], force: :cascade do |t|
17
17
  t.integer "emp_no", null: false
18
18
  t.integer "salary", null: false
19
- t.date "from_date", null: false
20
- t.date "to_date", null: false
19
+ t.date "from_date", null: false
20
+ t.date "to_date", null: false
21
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
21
22
  end
22
-
23
- <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
24
23
  EOS
25
24
  }
26
25
  end
@@ -40,22 +39,21 @@ describe 'Ridgepole::Client#dump' do
40
39
 
41
40
  it {
42
41
  expect(subject.dump).to match_fuzzy erbh(<<-EOS)
43
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('5.1', default: nil) %>, force: :cascade do |t|
44
- t.date "birth_date", null: false
42
+ create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond(5.1, default: nil) %>, force: :cascade do |t|
43
+ t.date "birth_date", null: false
45
44
  t.string "first_name", limit: 14, null: false
46
- t.string "last_name", limit: 16, null: false
47
- t.string "gender", limit: 1, null: false
48
- t.date "hire_date", null: false
45
+ t.string "last_name", limit: 16, null: false
46
+ t.string "gender", limit: 1, null: false
47
+ t.date "hire_date", null: false
49
48
  end
50
49
 
51
50
  create_table "salaries", primary_key: ["emp_no", "from_date"], force: :cascade do |t|
52
51
  t.integer "emp_no", null: false
53
52
  t.integer "salary", null: false
54
- t.date "from_date", null: false
55
- t.date "to_date", null: false
53
+ t.date "from_date", null: false
54
+ t.date "to_date", null: false
55
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
56
56
  end
57
-
58
- <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
59
57
  EOS
60
58
  }
61
59
  end
@@ -5,70 +5,63 @@ describe 'Ridgepole::Client#dump' do
5
5
 
6
6
  it {
7
7
  expect(subject.dump).to match_fuzzy erbh(<<-EOS)
8
- create_table "clubs", <%= i cond('5.1', id: :integer) %>, unsigned: true, force: :cascade do |t|
8
+ create_table "clubs", <%= i cond(5.1, id: :integer) %>, unsigned: true, force: :cascade do |t|
9
9
  t.string "name", default: "", null: false
10
+ t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
10
11
  end
11
12
 
12
- <%= add_index "clubs", ["name"], {name: "idx_name", unique: true} + cond('5.0', using: :btree) %>
13
-
14
13
  create_table "departments", primary_key: "dept_no", id: :string, limit: 4, force: :cascade do |t|
15
14
  t.string "dept_name", limit: 40, null: false
15
+ t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
16
16
  end
17
17
 
18
- <%= add_index "departments", ["dept_name"], {name: "dept_name", unique: true} + cond('5.0', using: :btree) %>
19
-
20
18
  create_table "dept_emp", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
21
19
  t.integer "emp_no", null: false
22
- t.string "dept_no", limit: 4, null: false
23
- t.date "from_date", null: false
24
- t.date "to_date", null: false
20
+ t.string "dept_no", limit: 4, null: false
21
+ t.date "from_date", null: false
22
+ t.date "to_date", null: false
23
+ t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
24
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
25
25
  end
26
26
 
27
- <%= add_index "dept_emp", ["dept_no"], {name: "dept_no"} + cond('5.0', using: :btree) %>
28
- <%= add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree %>
29
-
30
27
  create_table "dept_manager", primary_key: ["emp_no", "dept_no"], force: :cascade do |t|
31
- t.string "dept_no", limit: 4, null: false
28
+ t.string "dept_no", limit: 4, null: false
32
29
  t.integer "emp_no", null: false
33
- t.date "from_date", null: false
34
- t.date "to_date", null: false
30
+ t.date "from_date", null: false
31
+ t.date "to_date", null: false
32
+ t.index ["dept_no"], name: "dept_no", <%= i cond(5.0, using: :btree) %>
33
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
35
34
  end
36
35
 
37
- <%= add_index "dept_manager", ["dept_no"], {name: "dept_no"} + cond('5.0', using: :btree) %>
38
- <%= add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree %>
39
-
40
- create_table "employee_clubs", <%= i cond('5.1', id: :integer) %>, unsigned: true, force: :cascade do |t|
41
- t.integer "emp_no", null: false, unsigned: true
36
+ create_table "employee_clubs", <%= i cond(5.1, id: :integer) %>, unsigned: true, force: :cascade do |t|
37
+ t.integer "emp_no", null: false, unsigned: true
42
38
  t.integer "club_id", null: false, unsigned: true
39
+ t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id", <%= i cond(5.0, using: :btree) %>
43
40
  end
44
41
 
45
- <%= add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree %>
46
-
47
- create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond('5.1', default: nil) %>, force: :cascade do |t|
48
- t.date "birth_date", null: false
42
+ create_table "employees", primary_key: "emp_no", id: :integer, <%= i cond(5.1, default: nil) %>, force: :cascade do |t|
43
+ t.date "birth_date", null: false
49
44
  t.string "first_name", limit: 14, null: false
50
- t.string "last_name", limit: 16, null: false
51
- t.string "gender", limit: 1, null: false
52
- t.date "hire_date", null: false
45
+ t.string "last_name", limit: 16, null: false
46
+ t.string "gender", limit: 1, null: false
47
+ t.date "hire_date", null: false
53
48
  end
54
49
 
55
50
  create_table "salaries", primary_key: ["emp_no", "from_date"], force: :cascade do |t|
56
51
  t.integer "emp_no", null: false
57
52
  t.integer "salary", null: false
58
- t.date "from_date", null: false
59
- t.date "to_date", null: false
53
+ t.date "from_date", null: false
54
+ t.date "to_date", null: false
55
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
60
56
  end
61
57
 
62
- <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
63
-
64
58
  create_table "titles", primary_key: ["emp_no", "title", "from_date"], force: :cascade do |t|
65
59
  t.integer "emp_no", null: false
66
- t.string "title", limit: 50, null: false
67
- t.date "from_date", null: false
60
+ t.string "title", limit: 50, null: false
61
+ t.date "from_date", null: false
68
62
  t.date "to_date"
63
+ t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
69
64
  end
70
-
71
- <%= add_index "titles", ["emp_no"], name: "emp_no", using: :btree %>
72
65
  EOS
73
66
  }
74
67
  end
@@ -2,8 +2,8 @@ describe 'Ridgepole::Client#dump' do
2
2
  let(:actual_dsl) {
3
3
  erbh(<<-'EOS')
4
4
  create_table "books", unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='\"london\" bridge \"is\" falling \"down\"'" do |t|
5
- t.string "title", null: false
6
- t.integer "author_id", null: false
5
+ t.string "title", null: false
6
+ t.integer "author_id", null: false
7
7
  t.datetime "created_at"
8
8
  t.datetime "updated_at"
9
9
  end
@@ -13,9 +13,9 @@ describe 'Ridgepole::Client#dump' do
13
13
  context 'when without table options' do
14
14
  let(:expected_dsl) {
15
15
  erbh(<<-EOS)
16
- create_table "books", <%= i cond('5.1', id: :bigint) %>, unsigned: true, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
17
- t.string "title", null: false
18
- t.integer "author_id", null: false
16
+ create_table "books", <%= i cond(5.1, id: :bigint) %>, unsigned: true, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
17
+ t.string "title", null: false
18
+ t.integer "author_id", null: false
19
19
  t.datetime "created_at"
20
20
  t.datetime "updated_at"
21
21
  end
@@ -2,46 +2,99 @@ describe 'Ridgepole::Client#diff -> migrate' do
2
2
  context 'when change fk' do
3
3
  let(:actual_dsl) {
4
4
  erbh(<<-EOS)
5
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
6
- end
7
-
8
- create_table "child", force: :cascade do |t|
9
- t.integer "parent_id"
10
- end
5
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
6
+ end
11
7
 
12
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
8
+ create_table "child", force: :cascade do |t|
9
+ t.integer "parent_id"
10
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
11
+ end
13
12
 
14
- add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
13
+ add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
15
14
  EOS
16
15
  }
17
16
 
18
17
  let(:sorted_actual_dsl) {
19
18
  erbh(<<-EOS)
20
- create_table "child", force: :cascade do |t|
21
- t.integer "parent_id"
22
- end
23
-
24
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
19
+ create_table "child", force: :cascade do |t|
20
+ t.integer "parent_id"
21
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
22
+ end
25
23
 
26
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
27
- end
24
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
25
+ end
28
26
 
29
- add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
27
+ add_foreign_key "child", "parent", name: "child_ibfk_1", on_delete: :cascade
30
28
  EOS
31
29
  }
32
30
 
33
31
  let(:expected_dsl) {
34
32
  erbh(<<-EOS)
35
- create_table "child", force: :cascade do |t|
36
- t.integer "parent_id"
37
- end
33
+ create_table "child", force: :cascade do |t|
34
+ t.integer "parent_id"
35
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
36
+ end
38
37
 
39
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
38
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
39
+ end
40
40
 
41
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
42
- end
41
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
42
+ EOS
43
+ }
44
+
45
+ before { subject.diff(actual_dsl).migrate }
46
+
47
+ subject { client }
48
+
49
+ it {
50
+ delta = subject.diff(expected_dsl)
51
+ expect(delta.differ?).to be_truthy
52
+ expect(subject.dump).to match_fuzzy sorted_actual_dsl
53
+ delta.migrate
54
+ expect(subject.dump).to match_fuzzy expected_dsl
55
+ }
56
+ end
57
+
58
+ context 'when change fk without name' do
59
+ let(:actual_dsl) {
60
+ erbh(<<-EOS)
61
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
62
+ end
63
+
64
+ create_table "child", force: :cascade do |t|
65
+ t.integer "parent_id"
66
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
67
+ end
68
+
69
+ add_foreign_key "child", "parent", on_delete: :cascade
70
+ EOS
71
+ }
72
+
73
+ let(:sorted_actual_dsl) {
74
+ erbh(<<-EOS)
75
+ create_table "child", force: :cascade do |t|
76
+ t.integer "parent_id"
77
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
78
+ end
79
+
80
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
81
+ end
82
+
83
+ add_foreign_key "child", "parent", on_delete: :cascade
84
+ EOS
85
+ }
86
+
87
+ let(:expected_dsl) {
88
+ erbh(<<-EOS)
89
+ create_table "child", force: :cascade do |t|
90
+ t.integer "parent_id"
91
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
92
+ end
93
+
94
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
95
+ end
43
96
 
44
- add_foreign_key "child", "parent", name: "child_ibfk_1"
97
+ add_foreign_key "child", "parent"
45
98
  EOS
46
99
  }
47
100
 
@@ -2,21 +2,19 @@ describe 'Ridgepole::Client#diff -> migrate' do
2
2
  context 'when create fk' do
3
3
  let(:actual_dsl) {
4
4
  erbh(<<-EOS)
5
- create_table "child", force: :cascade do |t|
6
- t.integer "parent_id"
7
- end
8
-
9
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
5
+ create_table "child", force: :cascade do |t|
6
+ t.integer "parent_id"
7
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
8
+ end
10
9
 
11
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
12
- end
10
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
11
+ end
13
12
  EOS
14
13
  }
15
14
 
16
15
  let(:expected_dsl) {
17
16
  erbh(actual_dsl + <<-EOS)
18
-
19
- add_foreign_key "child", "parent", name: "child_ibfk_1"
17
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
20
18
  EOS
21
19
  }
22
20
 
@@ -54,31 +52,29 @@ add_foreign_key "child", "parent", name: "child_ibfk_1"
54
52
  context 'when create fk when create table' do
55
53
  let(:dsl) {
56
54
  erbh(<<-EOS)
57
- create_table "child", force: :cascade do |t|
58
- t.integer "parent_id"
59
- end
60
-
61
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
55
+ create_table "child", force: :cascade do |t|
56
+ t.integer "parent_id"
57
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
58
+ end
62
59
 
63
- add_foreign_key "child", "parent", name: "child_ibfk_1"
60
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
64
61
 
65
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
66
- end
62
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
63
+ end
67
64
  EOS
68
65
  }
69
66
 
70
67
  let(:sorted_dsl) {
71
68
  erbh(<<-EOS)
72
- create_table "child", force: :cascade do |t|
73
- t.integer "parent_id"
74
- end
75
-
76
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
69
+ create_table "child", force: :cascade do |t|
70
+ t.integer "parent_id"
71
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
72
+ end
77
73
 
78
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
79
- end
74
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
75
+ end
80
76
 
81
- add_foreign_key "child", "parent", name: "child_ibfk_1"
77
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
82
78
  EOS
83
79
  }
84
80
 
@@ -96,18 +92,17 @@ add_foreign_key "child", "parent", name: "child_ibfk_1"
96
92
  context 'already defined' do
97
93
  let(:dsl) {
98
94
  erbh(<<-EOS)
99
- create_table "child", force: :cascade do |t|
100
- t.integer "parent_id", unsigned: true
101
- end
102
-
103
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
95
+ create_table "child", force: :cascade do |t|
96
+ t.integer "parent_id", unsigned: true
97
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
98
+ end
104
99
 
105
- add_foreign_key "child", "parent", name: "child_ibfk_1"
100
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
106
101
 
107
- add_foreign_key "child", "parent", name: "child_ibfk_1"
102
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
108
103
 
109
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
110
- end
104
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
105
+ end
111
106
  EOS
112
107
  }
113
108
 
@@ -120,38 +115,63 @@ end
120
115
  }
121
116
  end
122
117
 
123
- context 'no name' do
124
- let(:dsl) {
118
+ context 'when create fk without name' do
119
+ let(:actual_dsl) {
125
120
  erbh(<<-EOS)
126
- create_table "child", force: :cascade do |t|
127
- t.integer "parent_id", unsigned: true
128
- end
129
-
130
- <%= add_index "child", ["parent_id"], {name: "par_id"} + cond('5.0', using: :btree) %>
121
+ create_table "child", force: :cascade do |t|
122
+ t.integer "parent_id"
123
+ t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
124
+ end
131
125
 
132
- add_foreign_key "child", "parent"
126
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
127
+ end
128
+ EOS
129
+ }
133
130
 
134
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
135
- end
131
+ let(:expected_dsl) {
132
+ erbh(actual_dsl + <<-EOS)
133
+ add_foreign_key "child", "parent"
136
134
  EOS
137
135
  }
138
136
 
137
+ before { subject.diff(actual_dsl).migrate }
139
138
  subject { client }
140
139
 
141
140
  it {
142
- expect {
143
- subject.diff(dsl)
144
- }.to raise_error('Foreign key name in `child` is undefined')
141
+ delta = subject.diff(expected_dsl)
142
+ expect(delta.differ?).to be_truthy
143
+ expect(subject.dump).to match_fuzzy actual_dsl
144
+ delta.migrate
145
+ expect(subject.dump).to match_fuzzy expected_dsl
146
+ }
147
+
148
+ it {
149
+ delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true, default_int_limit: 4)
150
+ expect(delta.differ?).to be_truthy
151
+ expect(delta.script).to match_fuzzy <<-EOS
152
+ remove_foreign_key("child", "parent")
153
+ EOS
154
+ }
155
+
156
+ it {
157
+ delta = client(bulk_change: true).diff(expected_dsl)
158
+ expect(delta.differ?).to be_truthy
159
+ expect(subject.dump).to match_fuzzy actual_dsl
160
+ expect(delta.script).to match_fuzzy <<-EOS
161
+ add_foreign_key("child", "parent", {})
162
+ EOS
163
+ delta.migrate
164
+ expect(subject.dump).to match_fuzzy expected_dsl
145
165
  }
146
166
  end
147
167
 
148
168
  context 'orphan fk' do
149
169
  let(:dsl) {
150
170
  erbh(<<-EOS)
151
- add_foreign_key "child", "parent", name: "child_ibfk_1"
171
+ add_foreign_key "child", "parent", name: "child_ibfk_1"
152
172
 
153
- create_table "parent", <%= i cond('5.1', id: :integer) %>, force: :cascade do |t|
154
- end
173
+ create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
174
+ end
155
175
  EOS
156
176
  }
157
177