ridgepole 0.6.0.beta2 → 0.6.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -0
  3. data/README.md +2 -0
  4. data/bin/ridgepole +16 -16
  5. data/lib/ridgepole/client.rb +6 -9
  6. data/lib/ridgepole/default_limit.rb +26 -0
  7. data/lib/ridgepole/delta.rb +2 -8
  8. data/lib/ridgepole/diff.rb +14 -10
  9. data/lib/ridgepole/version.rb +1 -1
  10. data/lib/ridgepole.rb +2 -10
  11. data/ridgepole.gemspec +1 -0
  12. data/spec/{bigint_pk → mysql/bigint_pk}/bigint_pkspec.rb +0 -0
  13. data/spec/{cli → mysql/cli}/config_spec.rb +3 -1
  14. data/spec/{cli → mysql/cli}/ridgepole_spec.rb +3 -0
  15. data/spec/{collation → mysql/collation}/collation_spec.rb +2 -0
  16. data/spec/{diff → mysql/diff}/diff2_spec.rb +2 -0
  17. data/spec/{diff → mysql/diff}/diff_spec.rb +2 -0
  18. data/spec/{dump → mysql/dump}/dump_class_method_spec.rb +2 -0
  19. data/spec/{dump → mysql/dump}/dump_some_tables_spec.rb +2 -0
  20. data/spec/{dump → mysql/dump}/dump_spec.rb +2 -0
  21. data/spec/{dump → mysql/dump}/dump_without_table_options_spec.rb +2 -0
  22. data/spec/{migrate_0 → mysql/fk}/migrate_change_fk_spec.rb +5 -3
  23. data/spec/{migrate_0 → mysql/fk}/migrate_create_fk_spec.rb +7 -5
  24. data/spec/{migrate_0 → mysql/fk}/migrate_drop_fk_spec.rb +6 -4
  25. data/spec/{migrate → mysql/migrate}/check_orphan_index_spec.rb +2 -0
  26. data/spec/{migrate → mysql/migrate}/migrate_add_column2_spec.rb +2 -0
  27. data/spec/{migrate → mysql/migrate}/migrate_add_column_spec.rb +2 -0
  28. data/spec/{migrate → mysql/migrate}/migrate_change_column2_spec.rb +2 -0
  29. data/spec/{migrate → mysql/migrate}/migrate_change_column3_spec.rb +2 -0
  30. data/spec/mysql/migrate/migrate_change_column4_spec.rb +83 -0
  31. data/spec/{migrate → mysql/migrate}/migrate_change_column_float_spec.rb +2 -0
  32. data/spec/{migrate → mysql/migrate}/migrate_change_column_spec.rb +2 -0
  33. data/spec/{migrate → mysql/migrate}/migrate_change_index2_spec.rb +2 -0
  34. data/spec/{migrate → mysql/migrate}/migrate_change_index3_spec.rb +2 -0
  35. data/spec/{migrate → mysql/migrate}/migrate_change_index4_spec.rb +2 -0
  36. data/spec/mysql/migrate/migrate_change_index5_spec.rb +78 -0
  37. data/spec/{migrate → mysql/migrate}/migrate_change_index_spec.rb +2 -0
  38. data/spec/{migrate → mysql/migrate}/migrate_change_table_option_spec.rb +2 -0
  39. data/spec/{migrate → mysql/migrate}/migrate_create_index_spec.rb +2 -0
  40. data/spec/{migrate → mysql/migrate}/migrate_create_table_spec.rb +2 -0
  41. data/spec/{migrate → mysql/migrate}/migrate_create_table_with_options_spec.rb +2 -0
  42. data/spec/{migrate → mysql/migrate}/migrate_drop_column_and_index_2_spec.rb +2 -0
  43. data/spec/{migrate → mysql/migrate}/migrate_drop_column_and_index_spec.rb +2 -0
  44. data/spec/{migrate → mysql/migrate}/migrate_drop_column_spec.rb +2 -0
  45. data/spec/{migrate → mysql/migrate}/migrate_drop_index_spec.rb +2 -0
  46. data/spec/{migrate → mysql/migrate}/migrate_drop_table_spec.rb +2 -0
  47. data/spec/{migrate → mysql/migrate}/migrate_duplicate_index_spec.rb +2 -0
  48. data/spec/{migrate → mysql/migrate}/migrate_duplicate_table_spec.rb +2 -0
  49. data/spec/{migrate → mysql/migrate}/migrate_empty_spec.rb +2 -0
  50. data/spec/{migrate → mysql/migrate}/migrate_execute_spec.rb +2 -0
  51. data/spec/{migrate → mysql/migrate}/migrate_merge_mode_spec.rb +2 -0
  52. data/spec/{migrate → mysql/migrate}/migrate_noop_spec.rb +2 -0
  53. data/spec/{migrate → mysql/migrate}/migrate_rename_column_spec.rb +2 -0
  54. data/spec/{migrate → mysql/migrate}/migrate_rename_table_spec.rb +2 -0
  55. data/spec/{migrate → mysql/migrate}/migrate_same_default_null_spec.rb +2 -0
  56. data/spec/{migrate → mysql/migrate}/migrate_same_spec.rb +2 -0
  57. data/spec/{migrate → mysql/migrate}/migrate_script_error_spec.rb +2 -0
  58. data/spec/{migrate → mysql/migrate}/migrate_skip_rename_column_spec.rb +2 -0
  59. data/spec/{migrate → mysql/migrate}/migrate_skip_rename_table_spec.rb +2 -0
  60. data/spec/{migrate → mysql/migrate}/migrate_with_ignore_tables_spec.rb +2 -0
  61. data/spec/{migrate → mysql/migrate}/migrate_with_pre_post_query_spec.rb +2 -0
  62. data/spec/{migrate → mysql/migrate}/migrate_with_tables_spec.rb +2 -0
  63. data/spec/{ridgepole_test_database.sql → mysql/ridgepole_test_database.sql} +0 -0
  64. data/spec/{ridgepole_test_tables.sql → mysql/ridgepole_test_tables.sql} +0 -0
  65. data/spec/postgresql/diff/diff_spec.rb +153 -0
  66. data/spec/postgresql/dump/dump_spec.rb +76 -0
  67. data/spec/postgresql/fk/migrate_change_fk_spec.rb +62 -0
  68. data/spec/postgresql/fk/migrate_create_fk_spec.rb +173 -0
  69. data/spec/postgresql/fk/migrate_drop_fk_spec.rb +114 -0
  70. data/spec/postgresql/migrate/migrate_add_column_spec.rb +220 -0
  71. data/spec/postgresql/migrate/migrate_change_column_spec.rb +203 -0
  72. data/spec/postgresql/migrate/migrate_change_index_spec.rb +193 -0
  73. data/spec/postgresql/migrate/migrate_create_table_spec.rb +103 -0
  74. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +185 -0
  75. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +180 -0
  76. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +125 -0
  77. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +116 -0
  78. data/spec/postgresql/migrate/migrate_rename_column_spec.rb +179 -0
  79. data/spec/postgresql/migrate/migrate_rename_table_spec.rb +199 -0
  80. data/spec/postgresql/migrate/migrate_same_spec.rb +84 -0
  81. data/spec/postgresql/ridgepole_test_database.sql +15 -0
  82. data/spec/postgresql/ridgepole_test_tables.sql +74 -0
  83. data/spec/spec_helper.rb +63 -7
  84. metadata +159 -104
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when change index (no change)' do
3
4
  let(:actual_dsl) {
@@ -87,3 +88,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
87
88
  }
88
89
  end
89
90
  end
91
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when change index without using (no change)' do
3
4
  let(:actual_dsl) {
@@ -175,3 +176,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
175
176
  }
176
177
  end
177
178
  end
179
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when change index (same name)' do
3
4
  let(:actual_dsl) {
@@ -114,3 +115,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
114
115
  }
115
116
  end
116
117
  end
118
+ end
@@ -0,0 +1,78 @@
1
+ unless postgresql?
2
+ describe 'Ridgepole::Client#diff -> migrate' do
3
+ context 'when change index (unique: false)' do
4
+ let(:actual_dsl) {
5
+ <<-RUBY
6
+ create_table "salaries"#{unsigned_if_enabled}, force: :cascade do |t|
7
+ t.integer "emp_no", limit: 4, null: false
8
+ t.integer "salary", limit: 4, null: false
9
+ t.date "from_date", null: false
10
+ t.date "to_date", null: false
11
+ end
12
+
13
+ add_index "salaries", ["emp_no", "id"], name: "emp_no", using: :btree
14
+ RUBY
15
+ }
16
+
17
+ let(:expected_dsl) {
18
+ <<-RUBY
19
+ create_table "salaries"#{unsigned_if_enabled}, force: :cascade do |t|
20
+ t.integer "emp_no", limit: 4, null: false
21
+ t.integer "salary", limit: 4, null: false
22
+ t.date "from_date", null: false
23
+ t.date "to_date", null: false
24
+ end
25
+
26
+ add_index "salaries", ["emp_no", "id"], unique: false, name: "emp_no", unique: false, using: :btree
27
+ RUBY
28
+ }
29
+
30
+ before { subject.diff(actual_dsl).migrate }
31
+ subject { client }
32
+
33
+ it {
34
+ delta = subject.diff(expected_dsl)
35
+ expect(delta.differ?).to be_falsy
36
+ }
37
+ end
38
+
39
+ context 'when change index (unique: true)' do
40
+ let(:actual_dsl) {
41
+ <<-RUBY
42
+ create_table "salaries"#{unsigned_if_enabled}, force: :cascade do |t|
43
+ t.integer "emp_no", limit: 4, null: false
44
+ t.integer "salary", limit: 4, null: false
45
+ t.date "from_date", null: false
46
+ t.date "to_date", null: false
47
+ end
48
+
49
+ add_index "salaries", ["emp_no", "id"], name: "emp_no", using: :btree
50
+ RUBY
51
+ }
52
+
53
+ let(:expected_dsl) {
54
+ <<-RUBY
55
+ create_table "salaries"#{unsigned_if_enabled}, force: :cascade do |t|
56
+ t.integer "emp_no", limit: 4, null: false
57
+ t.integer "salary", limit: 4, null: false
58
+ t.date "from_date", null: false
59
+ t.date "to_date", null: false
60
+ end
61
+
62
+ add_index "salaries", ["emp_no", "id"], name: "emp_no", unique: true, using: :btree
63
+ RUBY
64
+ }
65
+
66
+ before { subject.diff(actual_dsl).migrate }
67
+ subject { client }
68
+
69
+ it {
70
+ delta = subject.diff(expected_dsl)
71
+ expect(delta.differ?).to be_truthy
72
+ expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
73
+ delta.migrate
74
+ expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
75
+ }
76
+ end
77
+ end
78
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when change index' do
3
4
  let(:dsl) {
@@ -261,3 +262,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
261
262
  }
262
263
  end
263
264
  end
265
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when change column' do
3
4
  let(:actual_dsl) {
@@ -44,3 +45,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
44
45
  }
45
46
  end
46
47
  end
48
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when create index' do
3
4
  let(:dsl) {
@@ -122,3 +123,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
122
123
  }
123
124
  end
124
125
  end
126
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when create table' do
3
4
  let(:dsl) {
@@ -101,3 +102,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
101
102
  }
102
103
  end
103
104
  end
105
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when create table' do
3
4
  let(:expected_dsl) {
@@ -27,3 +28,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
27
28
  }
28
29
  end
29
30
  end
31
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when drop column and index (2)' do
3
4
  let(:actual_dsl) {
@@ -150,3 +151,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
150
151
  }
151
152
  end
152
153
  end
154
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when drop column and index' do
3
4
  let(:actual_dsl) {
@@ -177,3 +178,4 @@ end
177
178
  }
178
179
  end
179
180
  end
181
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when drop column' do
3
4
  let(:actual_dsl) {
@@ -184,3 +185,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
184
185
  }
185
186
  end
186
187
  end
188
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when drop index' do
3
4
  let(:dsl) {
@@ -122,3 +123,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
122
123
  }
123
124
  end
124
125
  end
126
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when drop table' do
3
4
  let(:dsl) {
@@ -114,3 +115,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
114
115
  }
115
116
  end
116
117
  end
118
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when index already defined' do
3
4
  let(:dsl) {
@@ -23,3 +24,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
23
24
  }
24
25
  end
25
26
  end
27
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when table already defined' do
3
4
  let(:dsl) {
@@ -33,3 +34,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
33
34
  }
34
35
  end
35
36
  end
37
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when database is empty' do
3
4
  let(:actual_dsl) { '' }
@@ -103,3 +104,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
103
104
  }
104
105
  end
105
106
  end
107
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when execute' do
3
4
  let(:dsl) {
@@ -292,3 +293,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
292
293
  }
293
294
  end
294
295
  end
296
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when marge table' do
3
4
  let(:actual_dsl) {
@@ -160,3 +161,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
160
161
  }
161
162
  end
162
163
  end
164
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when no operation' do
3
4
  let(:actual_dsl) { '' }
@@ -235,3 +236,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
235
236
  }
236
237
  end
237
238
  end
239
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when rename column' do
3
4
  let(:actual_dsl) {
@@ -206,3 +207,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
206
207
  }
207
208
  end
208
209
  end
210
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when rename table' do
3
4
  let(:actual_dsl) {
@@ -223,3 +224,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
223
224
  }
224
225
  end
225
226
  end
227
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when database and definition are same (default null / nothing -> null:true)' do
3
4
  let(:actual_dsl) {
@@ -73,3 +74,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
73
74
  }
74
75
  end
75
76
  end
77
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when database and definition are same' do
3
4
  let(:dsl) {
@@ -81,3 +82,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
81
82
  }
82
83
  end
83
84
  end
85
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when there is an error in the script' do
3
4
  let(:actual_dsl) { '' }
@@ -87,3 +88,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
87
88
  }
88
89
  end
89
90
  end
91
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when rename column' do
3
4
  let(:actual_dsl) {
@@ -155,3 +156,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
155
156
  }
156
157
  end
157
158
  end
159
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when rename table' do
3
4
  let(:actual_dsl) {
@@ -155,3 +156,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
155
156
  }
156
157
  end
157
158
  end
159
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when with ignore tables option (same)' do
3
4
  let(:current_schema) {
@@ -153,3 +154,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
153
154
  }
154
155
  end
155
156
  end
157
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'migrate with pre/post query' do
3
4
  let(:actual_dsl) { '' }
@@ -163,3 +164,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
163
164
  }
164
165
  end
165
166
  end
167
+ end
@@ -1,3 +1,4 @@
1
+ unless postgresql?
1
2
  describe 'Ridgepole::Client#diff -> migrate' do
2
3
  context 'when with tables option (same)' do
3
4
  let(:current_schema) {
@@ -153,3 +154,4 @@ describe 'Ridgepole::Client#diff -> migrate' do
153
154
  }
154
155
  end
155
156
  end
157
+ end
@@ -0,0 +1,153 @@
1
+ if postgresql?
2
+ describe 'Ridgepole::Client.diff' do
3
+ context 'when change column' do
4
+ let(:actual_dsl) {
5
+ <<-RUBY
6
+ create_table "clubs", force: :cascade do |t|
7
+ t.string "name", limit: 255, default: "", null: false
8
+ end
9
+
10
+ add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
11
+
12
+ create_table "departments", primary_key: "dept_no", force: :cascade do |t|
13
+ t.string "dept_name", limit: 40, null: false
14
+ end
15
+
16
+ add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
17
+
18
+ create_table "dept_emp", id: false, force: :cascade do |t|
19
+ t.integer "emp_no", 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
+ end
24
+
25
+ add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
26
+ add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
27
+
28
+ create_table "dept_manager", id: false, force: :cascade do |t|
29
+ t.string "dept_no", limit: 4, null: false
30
+ t.integer "emp_no", null: false
31
+ t.date "from_date", null: false
32
+ t.date "to_date", null: false
33
+ end
34
+
35
+ add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
36
+ add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
37
+
38
+ create_table "employee_clubs", force: :cascade do |t|
39
+ t.integer "emp_no", null: false
40
+ t.integer "club_id", null: false
41
+ end
42
+
43
+ add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
44
+
45
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
46
+ t.date "birth_date", null: false
47
+ t.string "first_name", limit: 14, null: false
48
+ t.string "last_name", limit: 16, null: false
49
+ t.date "hire_date", null: false
50
+ end
51
+
52
+ create_table "salaries", id: false, force: :cascade do |t|
53
+ t.integer "emp_no", null: false
54
+ t.integer "salary", null: false
55
+ t.date "from_date", null: false
56
+ t.date "to_date", null: false
57
+ end
58
+
59
+ add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
60
+
61
+ create_table "titles", id: false, force: :cascade do |t|
62
+ t.integer "emp_no", null: false
63
+ t.string "title", limit: 50, null: false
64
+ t.date "from_date", null: false
65
+ t.date "to_date"
66
+ end
67
+
68
+ add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
69
+ RUBY
70
+ }
71
+
72
+ let(:expected_dsl) {
73
+ <<-RUBY
74
+ create_table "clubs", force: :cascade do |t|
75
+ t.string "name", limit: 255, default: "", null: false
76
+ end
77
+
78
+ add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
79
+
80
+ create_table "departments", primary_key: "dept_no", force: :cascade do |t|
81
+ t.string "dept_name", limit: 40, null: false
82
+ end
83
+
84
+ add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
85
+
86
+ create_table "dept_emp", id: false, force: :cascade do |t|
87
+ t.integer "emp_no", null: false
88
+ t.string "dept_no", limit: 4, null: false
89
+ t.date "from_date", null: false
90
+ t.date "to_date", null: false
91
+ end
92
+
93
+ add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
94
+ add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
95
+
96
+ create_table "dept_manager", id: false, force: :cascade do |t|
97
+ t.string "dept_no", limit: 4, null: false
98
+ t.integer "emp_no", null: false
99
+ t.date "from_date", null: false
100
+ t.date "to_date", null: false
101
+ end
102
+
103
+ add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
104
+ add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
105
+
106
+ create_table "employee_clubs", force: :cascade do |t|
107
+ t.integer "emp_no", null: false
108
+ t.integer "club_id", null: true
109
+ end
110
+
111
+ add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
112
+
113
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
114
+ t.date "birth_date", null: false
115
+ t.string "first_name", limit: 14, null: false
116
+ t.string "last_name", limit: 20, default: "XXX", null: false
117
+ t.date "hire_date", null: false
118
+ end
119
+
120
+ create_table "salaries", id: false, force: :cascade do |t|
121
+ t.integer "emp_no", null: false
122
+ t.integer "salary", null: false
123
+ t.date "from_date", null: false
124
+ t.date "to_date", null: false
125
+ end
126
+
127
+ add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
128
+
129
+ create_table "titles", id: false, force: :cascade do |t|
130
+ t.integer "emp_no", null: false
131
+ t.string "title", limit: 50, null: false
132
+ t.date "from_date", null: false
133
+ t.date "to_date"
134
+ end
135
+
136
+ add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
137
+ RUBY
138
+ }
139
+
140
+ subject { Ridgepole::Client }
141
+
142
+ it {
143
+ delta = subject.diff(actual_dsl, expected_dsl, enable_mysql_unsigned: true)
144
+ expect(delta.differ?).to be_truthy
145
+ expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
146
+ change_column("employee_clubs", "club_id", :integer, {:null=>true, :default=>nil})
147
+
148
+ change_column("employees", "last_name", :string, {:limit=>20, :default=>"XXX", :null=>false})
149
+ RUBY
150
+ }
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,76 @@
1
+ if postgresql?
2
+ describe 'Ridgepole::Client#dump' do
3
+ context 'when there is a tables' do
4
+ before { restore_tables }
5
+ subject { client }
6
+
7
+ it {
8
+ expect(subject.dump).to eq <<-RUBY.strip_heredoc.strip
9
+ create_table "clubs", force: :cascade do |t|
10
+ t.string "name", limit: 255, default: "", null: false
11
+ end
12
+
13
+ add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
14
+
15
+ create_table "departments", primary_key: "dept_no", force: :cascade do |t|
16
+ t.string "dept_name", limit: 40, null: false
17
+ end
18
+
19
+ add_index "departments", ["dept_name"], name: "idx_dept_name", unique: true, using: :btree
20
+
21
+ create_table "dept_emp", id: false, force: :cascade do |t|
22
+ t.integer "emp_no", null: false
23
+ t.string "dept_no", limit: 4, null: false
24
+ t.date "from_date", null: false
25
+ t.date "to_date", null: false
26
+ end
27
+
28
+ add_index "dept_emp", ["dept_no"], name: "idx_dept_emp_dept_no", using: :btree
29
+ add_index "dept_emp", ["emp_no"], name: "idx_dept_emp_emp_no", using: :btree
30
+
31
+ create_table "dept_manager", id: false, force: :cascade do |t|
32
+ t.string "dept_no", limit: 4, null: false
33
+ t.integer "emp_no", null: false
34
+ t.date "from_date", null: false
35
+ t.date "to_date", null: false
36
+ end
37
+
38
+ add_index "dept_manager", ["dept_no"], name: "idx_dept_manager_dept_no", using: :btree
39
+ add_index "dept_manager", ["emp_no"], name: "idx_dept_manager_emp_no", using: :btree
40
+
41
+ create_table "employee_clubs", force: :cascade do |t|
42
+ t.integer "emp_no", null: false
43
+ t.integer "club_id", null: false
44
+ end
45
+
46
+ add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_employee_clubs_emp_no_club_id", using: :btree
47
+
48
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
49
+ t.date "birth_date", null: false
50
+ t.string "first_name", limit: 14, null: false
51
+ t.string "last_name", limit: 16, null: false
52
+ t.date "hire_date", null: false
53
+ end
54
+
55
+ create_table "salaries", id: false, force: :cascade do |t|
56
+ t.integer "emp_no", null: false
57
+ t.integer "salary", null: false
58
+ t.date "from_date", null: false
59
+ t.date "to_date", null: false
60
+ end
61
+
62
+ add_index "salaries", ["emp_no"], name: "idx_salaries_emp_no", using: :btree
63
+
64
+ create_table "titles", id: false, force: :cascade do |t|
65
+ t.integer "emp_no", null: false
66
+ t.string "title", limit: 50, null: false
67
+ t.date "from_date", null: false
68
+ t.date "to_date"
69
+ end
70
+
71
+ add_index "titles", ["emp_no"], name: "idx_titles_emp_no", using: :btree
72
+ RUBY
73
+ }
74
+ end
75
+ end
76
+ end