ridgepole 0.6.5.beta → 0.6.5.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Appraisals +1 -1
  4. data/README.md +3 -1
  5. data/gemfiles/activerecord_5.0.gemfile +1 -1
  6. data/lib/ridgepole/client.rb +5 -1
  7. data/lib/ridgepole/delta.rb +21 -5
  8. data/lib/ridgepole/diff.rb +13 -2
  9. data/lib/ridgepole/dsl_parser.rb +38 -3
  10. data/lib/ridgepole/dumper.rb +2 -2
  11. data/lib/ridgepole/ext/abstract_mysql_adapter/disable_table_options.rb +21 -0
  12. data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +28 -0
  13. data/lib/ridgepole/version.rb +1 -1
  14. data/ridgepole.gemspec +3 -3
  15. data/spec/erb_helper.rb +43 -0
  16. data/spec/mysql/bigint_pk/bigint_pk_spec.rb +9 -9
  17. data/spec/mysql/collation/collation_spec.rb +39 -37
  18. data/spec/mysql/default_lambda/default_lambda_spec.rb +162 -0
  19. data/spec/mysql/diff/diff2_spec.rb +10 -10
  20. data/spec/mysql/diff/diff_spec.rb +6 -6
  21. data/spec/mysql/dump/dump_class_method_spec.rb +56 -39
  22. data/spec/mysql/dump/dump_some_tables_spec.rb +21 -13
  23. data/spec/mysql/dump/dump_spec.rb +49 -36
  24. data/spec/mysql/dump/dump_without_table_options_spec.rb +27 -9
  25. data/spec/mysql/fk/migrate_change_fk_spec.rb +17 -11
  26. data/spec/mysql/fk/migrate_create_fk_spec.rb +20 -18
  27. data/spec/mysql/fk/migrate_drop_fk_spec.rb +30 -16
  28. data/spec/mysql/migrate/migrate_add_column2_spec.rb +10 -8
  29. data/spec/mysql/migrate/migrate_add_column_spec.rb +49 -61
  30. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +46 -58
  31. data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +46 -58
  32. data/spec/mysql/migrate/migrate_change_column2_spec.rb +12 -24
  33. data/spec/mysql/migrate/migrate_change_column3_spec.rb +18 -30
  34. data/spec/mysql/migrate/migrate_change_column5_spec.rb +8 -20
  35. data/spec/mysql/migrate/migrate_change_column6_spec.rb +8 -8
  36. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +20 -20
  37. data/spec/mysql/migrate/migrate_change_column_float_spec.rb +2 -2
  38. data/spec/mysql/migrate/migrate_change_column_spec.rb +54 -68
  39. data/spec/mysql/migrate/migrate_change_index2_spec.rb +14 -14
  40. data/spec/mysql/migrate/migrate_change_index3_spec.rb +28 -28
  41. data/spec/mysql/migrate/migrate_change_index4_spec.rb +26 -38
  42. data/spec/mysql/migrate/migrate_change_index5_spec.rb +20 -32
  43. data/spec/mysql/migrate/migrate_change_index6_spec.rb +63 -75
  44. data/spec/mysql/migrate/migrate_change_index_spec.rb +62 -74
  45. data/spec/mysql/migrate/migrate_change_table_option_spec.rb +8 -20
  46. data/spec/mysql/migrate/migrate_create_index2_spec.rb +98 -53
  47. data/spec/mysql/migrate/migrate_create_index_spec.rb +84 -39
  48. data/spec/mysql/migrate/migrate_create_table_spec.rb +69 -39
  49. data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +69 -39
  50. data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +47 -59
  51. data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +43 -55
  52. data/spec/mysql/migrate/migrate_drop_column_spec.rb +48 -60
  53. data/spec/mysql/migrate/migrate_drop_index_spec.rb +84 -39
  54. data/spec/mysql/migrate/migrate_drop_table_spec.rb +76 -46
  55. data/spec/mysql/migrate/migrate_empty_spec.rb +24 -36
  56. data/spec/mysql/migrate/migrate_execute_spec.rb +30 -32
  57. data/spec/mysql/migrate/migrate_log_file_spec.rb +69 -39
  58. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +48 -48
  59. data/spec/mysql/migrate/migrate_noop_spec.rb +23 -13
  60. data/spec/mysql/migrate/migrate_rename_column_spec.rb +48 -60
  61. data/spec/mysql/migrate/migrate_rename_table_spec.rb +56 -68
  62. data/spec/mysql/migrate/migrate_same_default_null_spec.rb +8 -20
  63. data/spec/mysql/migrate/migrate_same_spec.rb +49 -31
  64. data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +48 -60
  65. data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +48 -60
  66. data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +34 -34
  67. data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +84 -39
  68. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +84 -39
  69. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +84 -0
  70. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +14 -8
  71. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +15 -27
  72. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +10 -10
  73. data/spec/postgresql/dump/dump_spec.rb +40 -16
  74. data/spec/postgresql/fk/migrate_change_fk_spec.rb +6 -6
  75. data/spec/postgresql/fk/migrate_create_fk_spec.rb +11 -11
  76. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +8 -8
  77. data/spec/postgresql/migrate/migrate_add_column_spec.rb +20 -20
  78. data/spec/postgresql/migrate/migrate_change_column_spec.rb +20 -20
  79. data/spec/postgresql/migrate/migrate_change_index_spec.rb +20 -20
  80. data/spec/postgresql/migrate/migrate_create_table_spec.rb +52 -12
  81. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +20 -20
  82. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +18 -18
  83. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +69 -13
  84. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +55 -13
  85. data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +3 -1
  86. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +20 -20
  87. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +24 -24
  88. data/spec/postgresql/migrate/migrate_same_spec.rb +40 -16
  89. data/spec/postgresql/ridgepole_test_tables.sql +3 -0
  90. data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +6 -6
  91. data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +11 -11
  92. data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +8 -8
  93. data/spec/spec_condition.rb +14 -2
  94. data/spec/spec_helper.rb +12 -11
  95. data/spec/string_ext.rb +2 -0
  96. metadata +16 -9
  97. data/lib/ridgepole/ext/abstract_mysql_adapter.rb +0 -26
@@ -1,17 +1,26 @@
1
1
  describe 'Ridgepole::Client#diff -> migrate' do
2
2
  let(:template_variables) {
3
3
  opts = {
4
- unsigned: {},
5
4
  sql_int_pk_type: 'int(11) auto_increment PRIMARY KEY',
6
5
  sql_int_type: 'int(11)',
7
6
  sql_uint_type: 'int(11)',
8
7
  }
9
8
 
10
9
  if condition(:mysql_awesome_enabled)
11
- opts[:unsigned] = {unsigned: true}
12
- opts[:sql_int_pk_type] = 'int PRIMARY KEY AUTO_INCREMENT'
13
- opts[:sql_int_type] = 'int'
14
- opts[:sql_uint_type] = 'int unsigned'
10
+ opts.merge!(
11
+ sql_int_pk_type: 'int PRIMARY KEY AUTO_INCREMENT',
12
+ sql_int_type: 'int',
13
+ sql_uint_type: 'int unsigned'
14
+ )
15
+ end
16
+
17
+ if condition(:activerecord_5)
18
+ opts.merge!(
19
+ sql_int_pk_type: 'int AUTO_INCREMENT PRIMARY KEY',
20
+ sql_int_type: 'int',
21
+ sql_uint_type: 'int unsigned',
22
+ using_btree: 'USING btree'
23
+ )
15
24
  end
16
25
 
17
26
  opts
@@ -125,22 +134,23 @@ describe 'Ridgepole::Client#diff -> migrate' do
125
134
  expect(migrated).to be_truthy
126
135
  expect(subject.dump).to match_fuzzy actual_dsl
127
136
 
128
- expect(sql).to match_fuzzy erbh(<<-EOS, template_variables)
137
+ # XXX:
138
+ expect(sql.gsub('`', '')).to match_fuzzy erbh(<<-EOS, template_variables).gsub('`', '')
129
139
  CREATE TABLE `clubs` (`id` <%= @sql_int_pk_type %>, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
130
- ALTER TABLE `clubs` ADD UNIQUE INDEX idx_name (`name`)
140
+ ALTER TABLE `clubs` ADD UNIQUE INDEX `idx_name` <%= @using_btree %> (`name`)
131
141
  CREATE TABLE `departments` (`dept_no` <%= @sql_int_pk_type %>, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
132
- ALTER TABLE `departments` ADD UNIQUE INDEX dept_name (`dept_name`)
142
+ ALTER TABLE `departments` ADD UNIQUE INDEX `dept_name` <%= @using_btree %> (`dept_name`)
133
143
  CREATE TABLE `dept_emp` (`emp_no` <%= @sql_int_type %> NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
134
- ALTER TABLE `dept_emp` ADD INDEX dept_no (`dept_no`), ADD INDEX emp_no (`emp_no`)
144
+ ALTER TABLE `dept_emp` ADD INDEX `dept_no` <%= @using_btree %> (`dept_no`), ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
135
145
  CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
136
- ALTER TABLE `dept_manager` ADD INDEX dept_no (`dept_no`), ADD INDEX emp_no (`emp_no`)
146
+ ALTER TABLE `dept_manager` ADD INDEX `dept_no` <%= @using_btree %> (`dept_no`), ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
137
147
  CREATE TABLE `employee_clubs` (`id` <%= @sql_int_pk_type %>, `emp_no` <%= @sql_uint_type %> NOT NULL, `club_id` <%= @sql_uint_type %> NOT NULL) ENGINE=InnoDB
138
- ALTER TABLE `employee_clubs` ADD INDEX idx_emp_no_club_id (`emp_no`, `club_id`)
148
+ ALTER TABLE `employee_clubs` ADD INDEX `idx_emp_no_club_id` <%= @using_btree %> (`emp_no`, `club_id`)
139
149
  CREATE TABLE `employees` (`emp_no` <%= @sql_int_pk_type %>, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` varchar(1) NOT NULL, `hire_date` date NOT NULL) ENGINE=InnoDB
140
150
  CREATE TABLE `salaries` (`emp_no` <%= @sql_int_type %> NOT NULL, `salary` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
141
- ALTER TABLE `salaries` ADD INDEX emp_no (`emp_no`)
151
+ ALTER TABLE `salaries` ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
142
152
  CREATE TABLE `titles` (`emp_no` <%= @sql_int_type %> NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
143
- ALTER TABLE `titles` ADD INDEX emp_no (`emp_no`)
153
+ ALTER TABLE `titles` ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
144
154
  EOS
145
155
  }
146
156
  end
@@ -1,59 +1,47 @@
1
1
  describe 'Ridgepole::Client#diff -> migrate' do
2
- let(:template_variables) {
3
- opts = {
4
- unsigned: {}
5
- }
6
-
7
- if condition(:mysql_awesome_enabled)
8
- opts[:unsigned] = {unsigned: true}
9
- end
10
-
11
- opts
12
- }
13
-
14
2
  context 'when rename column' do
15
3
  let(:actual_dsl) {
16
- erbh(<<-EOS, template_variables)
17
- create_table "clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
18
- t.string "name", limit: 255, default: "", null: false
4
+ erbh(<<-EOS)
5
+ create_table "clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
6
+ t.string "name", <%= i limit(255) + {default: "", null: false} %>
19
7
  end
20
8
 
21
- add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
9
+ <%= add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree %>
22
10
 
23
- create_table "departments", primary_key: "dept_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
11
+ create_table "departments", primary_key: "dept_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
24
12
  t.string "dept_name", limit: 40, null: false
25
13
  end
26
14
 
27
- add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
15
+ <%= add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree %>
28
16
 
29
17
  create_table "dept_emp", id: false, force: :cascade do |t|
30
- t.integer "emp_no", limit: 4, null: false
31
- t.string "dept_no", limit: 4, null: false
18
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
19
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
32
20
  t.date "from_date", null: false
33
21
  t.date "to_date", null: false
34
22
  end
35
23
 
36
- add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
37
- add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
24
+ <%= add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree %>
25
+ <%= add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree %>
38
26
 
39
27
  create_table "dept_manager", id: false, force: :cascade do |t|
40
- t.string "dept_no", limit: 4, null: false
41
- t.integer "emp_no", limit: 4, null: false
28
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
29
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
42
30
  t.date "from_date", null: false
43
31
  t.date "to_date", null: false
44
32
  end
45
33
 
46
- add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
47
- add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
34
+ <%= add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree %>
35
+ <%= add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree %>
48
36
 
49
- create_table "employee_clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
50
- t.integer "emp_no", <%= {limit: 4, null: false}.push(@unsigned).i %>
51
- t.integer "club_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
37
+ create_table "employee_clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
38
+ t.integer "emp_no", <%= i limit(4) + {null: false} + unsigned(true) %>
39
+ t.integer "club_id", <%= i limit(4) + {null: false} + unsigned(true) %>
52
40
  end
53
41
 
54
- add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
42
+ <%= add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree %>
55
43
 
56
- create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
44
+ create_table "employees", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
57
45
  t.date "birth_date", null: false
58
46
  t.string "first_name", limit: 14, null: false
59
47
  t.string "last_name", limit: 16, null: false
@@ -62,67 +50,67 @@ describe 'Ridgepole::Client#diff -> migrate' do
62
50
  end
63
51
 
64
52
  create_table "salaries", id: false, force: :cascade do |t|
65
- t.integer "emp_no", limit: 4, null: false
66
- t.integer "salary", limit: 4, null: false
53
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
54
+ t.integer "salary", <%= i limit(4) + {null: false} %>
67
55
  t.date "from_date", null: false
68
56
  t.date "to_date", null: false
69
57
  end
70
58
 
71
- add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
59
+ <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
72
60
 
73
61
  create_table "titles", id: false, force: :cascade do |t|
74
- t.integer "emp_no", limit: 4, null: false
62
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
75
63
  t.string "title", limit: 50, null: false
76
64
  t.date "from_date", null: false
77
65
  t.date "to_date"
78
66
  end
79
67
 
80
- add_index "titles", ["emp_no"], name: "emp_no", using: :btree
68
+ <%= add_index "titles", ["emp_no"], name: "emp_no", using: :btree %>
81
69
  EOS
82
70
  }
83
71
 
84
72
  let(:expected_dsl) {
85
- erbh(<<-EOS, template_variables)
86
- create_table "clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
87
- t.string "name", limit: 255, default: "", null: false
73
+ erbh(<<-EOS)
74
+ create_table "clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
75
+ t.string "name", <%= i limit(255) + {default: "", null: false} %>
88
76
  end
89
77
 
90
- add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
78
+ <%= add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree %>
91
79
 
92
- create_table "departments", primary_key: "dept_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
80
+ create_table "departments", primary_key: "dept_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
93
81
  t.string "dept_name", limit: 40, null: false
94
82
  end
95
83
 
96
- add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
84
+ <%= add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree %>
97
85
 
98
86
  create_table "dept_emp", id: false, force: :cascade do |t|
99
- t.integer "emp_no", limit: 4, null: false
100
- t.string "dept_no", limit: 4, null: false
87
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
88
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
101
89
  t.date "from_date2", null: false, renamed_from: 'from_date'
102
90
  t.date "to_date", null: false
103
91
  end
104
92
 
105
- add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
106
- add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
93
+ <%= add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree %>
94
+ <%= add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree %>
107
95
 
108
96
  create_table "dept_manager", id: false, force: :cascade do |t|
109
- t.string "dept_no", limit: 4, null: false
110
- t.integer "emp_no", limit: 4, null: false
97
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
98
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
111
99
  t.date "from_date", null: false
112
100
  t.date "to_date2", null: false, renamed_from: 'to_date'
113
101
  end
114
102
 
115
- add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
116
- add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
103
+ <%= add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree %>
104
+ <%= add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree %>
117
105
 
118
- create_table "employee_clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
119
- t.integer "emp_no", <%= {limit: 4, null: false}.push(@unsigned).i %>
120
- t.integer "club_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
106
+ create_table "employee_clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
107
+ t.integer "emp_no", <%= i limit(4) + {null: false} + unsigned(true) %>
108
+ t.integer "club_id", <%= i limit(4) + {null: false} + unsigned(true) %>
121
109
  end
122
110
 
123
- add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
111
+ <%= add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree %>
124
112
 
125
- create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
113
+ create_table "employees", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
126
114
  t.date "birth_date", null: false
127
115
  t.string "first_name", limit: 14, null: false
128
116
  t.string "last_name", limit: 16, null: false
@@ -131,22 +119,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
131
119
  end
132
120
 
133
121
  create_table "salaries", id: false, force: :cascade do |t|
134
- t.integer "emp_no", limit: 4, null: false
135
- t.integer "salary", limit: 4, null: false
122
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
123
+ t.integer "salary", <%= i limit(4) + {null: false} %>
136
124
  t.date "from_date", null: false
137
125
  t.date "to_date", null: false
138
126
  end
139
127
 
140
- add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
128
+ <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
141
129
 
142
130
  create_table "titles", id: false, force: :cascade do |t|
143
- t.integer "emp_no", limit: 4, null: false
131
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
144
132
  t.string "title", limit: 50, null: false
145
133
  t.date "from_date", null: false
146
134
  t.date "to_date"
147
135
  end
148
136
 
149
- add_index "titles", ["emp_no"], name: "emp_no", using: :btree
137
+ <%= add_index "titles", ["emp_no"], name: "emp_no", using: :btree %>
150
138
  EOS
151
139
  }
152
140
 
@@ -1,59 +1,47 @@
1
1
  describe 'Ridgepole::Client#diff -> migrate' do
2
- let(:template_variables) {
3
- opts = {
4
- unsigned: {}
5
- }
6
-
7
- if condition(:mysql_awesome_enabled)
8
- opts[:unsigned] = {unsigned: true}
9
- end
10
-
11
- opts
12
- }
13
-
14
2
  context 'when rename table' do
15
3
  let(:actual_dsl) {
16
- erbh(<<-EOS, template_variables)
17
- create_table "clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
18
- t.string "name", limit: 255, default: "", null: false
4
+ erbh(<<-EOS)
5
+ create_table "clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
6
+ t.string "name", <%= i limit(255) + {default: "", null: false} %>
19
7
  end
20
8
 
21
- add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
9
+ <%= add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree %>
22
10
 
23
- create_table "departments", primary_key: "dept_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
11
+ create_table "departments", primary_key: "dept_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
24
12
  t.string "dept_name", limit: 40, null: false
25
13
  end
26
14
 
27
- add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
15
+ <%= add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree %>
28
16
 
29
17
  create_table "dept_emp", id: false, force: :cascade do |t|
30
- t.integer "emp_no", limit: 4, null: false
31
- t.string "dept_no", limit: 4, null: false
18
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
19
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
32
20
  t.date "from_date", null: false
33
21
  t.date "to_date", null: false
34
22
  end
35
23
 
36
- add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
37
- add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
24
+ <%= add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree %>
25
+ <%= add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree %>
38
26
 
39
27
  create_table "dept_manager", id: false, force: :cascade do |t|
40
- t.string "dept_no", limit: 4, null: false
41
- t.integer "emp_no", limit: 4, null: false
28
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
29
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
42
30
  t.date "from_date", null: false
43
31
  t.date "to_date", null: false
44
32
  end
45
33
 
46
- add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
47
- add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
34
+ <%= add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree %>
35
+ <%= add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree %>
48
36
 
49
- create_table "employee_clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
50
- t.integer "emp_no", <%= {limit: 4, null: false}.push(@unsigned).i %>
51
- t.integer "club_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
37
+ create_table "employee_clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
38
+ t.integer "emp_no", <%= i limit(4) + {null: false} + unsigned(true) %>
39
+ t.integer "club_id", <%= i limit(4) + {null: false} + unsigned(true) %>
52
40
  end
53
41
 
54
- add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
42
+ <%= add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree %>
55
43
 
56
- create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
44
+ create_table "employees", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
57
45
  t.date "birth_date", null: false
58
46
  t.string "first_name", limit: 14, null: false
59
47
  t.string "last_name", limit: 16, null: false
@@ -62,67 +50,67 @@ describe 'Ridgepole::Client#diff -> migrate' do
62
50
  end
63
51
 
64
52
  create_table "salaries", id: false, force: :cascade do |t|
65
- t.integer "emp_no", limit: 4, null: false
66
- t.integer "salary", limit: 4, null: false
53
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
54
+ t.integer "salary", <%= i limit(4) + {null: false} %>
67
55
  t.date "from_date", null: false
68
56
  t.date "to_date", null: false
69
57
  end
70
58
 
71
- add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
59
+ <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
72
60
 
73
61
  create_table "titles", id: false, force: :cascade do |t|
74
- t.integer "emp_no", limit: 4, null: false
62
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
75
63
  t.string "title", limit: 50, null: false
76
64
  t.date "from_date", null: false
77
65
  t.date "to_date"
78
66
  end
79
67
 
80
- add_index "titles", ["emp_no"], name: "emp_no", using: :btree
68
+ <%= add_index "titles", ["emp_no"], name: "emp_no", using: :btree %>
81
69
  EOS
82
70
  }
83
71
 
84
72
  let(:expected_dsl) {
85
- erbh(<<-EOS, template_variables)
86
- create_table "clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
87
- t.string "name", limit: 255, default: "", null: false
73
+ erbh(<<-EOS)
74
+ create_table "clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
75
+ t.string "name", <%= i limit(255) + {default: "", null: false} %>
88
76
  end
89
77
 
90
- add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
78
+ <%= add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree %>
91
79
 
92
- create_table "departments", primary_key: "dept_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
80
+ create_table "departments", primary_key: "dept_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
93
81
  t.string "dept_name", limit: 40, null: false
94
82
  end
95
83
 
96
- add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
84
+ <%= add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree %>
97
85
 
98
86
  create_table "dept_emp", id: false, force: :cascade do |t|
99
- t.integer "emp_no", limit: 4, null: false
100
- t.string "dept_no", limit: 4, null: false
87
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
88
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
101
89
  t.date "from_date", null: false
102
90
  t.date "to_date", null: false
103
91
  end
104
92
 
105
- add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
106
- add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
93
+ <%= add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree %>
94
+ <%= add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree %>
107
95
 
108
96
  create_table "dept_manager", id: false, force: :cascade do |t|
109
- t.string "dept_no", limit: 4, null: false
110
- t.integer "emp_no", limit: 4, null: false
97
+ t.string "dept_no", <%= i limit(4) + {null: false} %>
98
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
111
99
  t.date "from_date", null: false
112
100
  t.date "to_date", null: false
113
101
  end
114
102
 
115
- add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
116
- add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
103
+ <%= add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree %>
104
+ <%= add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree %>
117
105
 
118
- create_table "employee_clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
119
- t.integer "emp_no", <%= {limit: 4, null: false}.push(@unsigned).i %>
120
- t.integer "club_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
106
+ create_table "employee_clubs", <%= i unsigned(true) + {force: :cascade} %> do |t|
107
+ t.integer "emp_no", <%= i limit(4) + {null: false} + unsigned(true) %>
108
+ t.integer "club_id", <%= i limit(4) + {null: false} + unsigned(true) %>
121
109
  end
122
110
 
123
- add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
111
+ <%= add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree %>
124
112
 
125
- create_table "employees2", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %>, renamed_from: 'employees' do |t|
113
+ create_table "employees2", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %>, renamed_from: 'employees' do |t|
126
114
  t.date "birth_date", null: false
127
115
  t.string "first_name", limit: 14, null: false
128
116
  t.string "last_name", limit: 16, null: false
@@ -131,22 +119,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
131
119
  end
132
120
 
133
121
  create_table "salaries", id: false, force: :cascade do |t|
134
- t.integer "emp_no", limit: 4, null: false
135
- t.integer "salary", limit: 4, null: false
122
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
123
+ t.integer "salary", <%= i limit(4) + {null: false} %>
136
124
  t.date "from_date", null: false
137
125
  t.date "to_date", null: false
138
126
  end
139
127
 
140
- add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
128
+ <%= add_index "salaries", ["emp_no"], name: "emp_no", using: :btree %>
141
129
 
142
130
  create_table "titles", id: false, force: :cascade do |t|
143
- t.integer "emp_no", limit: 4, null: false
131
+ t.integer "emp_no", <%= i limit(4) + {null: false} %>
144
132
  t.string "title", limit: 50, null: false
145
133
  t.date "from_date", null: false
146
134
  t.date "to_date"
147
135
  end
148
136
 
149
- add_index "titles", ["emp_no"], name: "emp_no", using: :btree
137
+ <%= add_index "titles", ["emp_no"], name: "emp_no", using: :btree %>
150
138
  EOS
151
139
  }
152
140
 
@@ -172,8 +160,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
172
160
 
173
161
  context 'when rename table (dry-run)' do
174
162
  let(:actual_dsl) {
175
- erbh(<<-EOS, template_variables)
176
- create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
163
+ erbh(<<-EOS)
164
+ create_table "employees", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
177
165
  t.date "birth_date", null: false
178
166
  t.string "first_name", limit: 14, null: false
179
167
  t.string "last_name", limit: 16, null: false
@@ -181,13 +169,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
181
169
  t.date "hire_date", null: false
182
170
  end
183
171
 
184
- add_index "employees", ["first_name"], name: "first_name", using: :btree
172
+ <%= add_index "employees", ["first_name"], name: "first_name", using: :btree %>
185
173
  EOS
186
174
  }
187
175
 
188
176
  let(:expected_dsl) {
189
- erbh(<<-EOS, template_variables)
190
- create_table "employees2", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %>, renamed_from: 'employees' do |t|
177
+ erbh(<<-EOS)
178
+ create_table "employees2", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %>, renamed_from: 'employees' do |t|
191
179
  t.date "birth_date", null: false
192
180
  t.string "first_name", limit: 14, null: false
193
181
  t.string "last_name", limit: 16, null: false
@@ -195,7 +183,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
195
183
  t.date "hire_date", null: false
196
184
  end
197
185
 
198
- add_index "employees2", ["first_name"], name: "first_name", using: :btree
186
+ <%= add_index "employees2", ["first_name"], name: "first_name", using: :btree %>
199
187
  EOS
200
188
  }
201
189
 
@@ -216,8 +204,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
216
204
  subject { client }
217
205
 
218
206
  let(:dsl) {
219
- erbh(<<-EOS, template_variables)
220
- create_table "employees2", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %>, renamed_from: 'not_employees' do |t|
207
+ erbh(<<-EOS)
208
+ create_table "employees2", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %>, renamed_from: 'not_employees' do |t|
221
209
  t.date "birth_date", null: false
222
210
  t.string "first_name", limit: 14, null: false
223
211
  t.string "last_name", limit: 16, null: false