ridgepole 0.6.1.beta → 0.6.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99f9de7d2f7d60587f7f52945d75c1cca48a0a84
4
- data.tar.gz: ac73999341deac1963b4aa2b64aa9fa25ca77644
3
+ metadata.gz: b4029af4151a350ba9a5b174b1f2aa8d1227a322
4
+ data.tar.gz: 48a6f31061a3872bfa71512eec682ec74a10ed07
5
5
  SHA512:
6
- metadata.gz: 33ce416732a85e04bfee72699ea2129d066fe5031dc499f32b9b6931101216521f7931e8ad882d94c1e3c7719f566399e8e411c367577036242c84c9d4bd5009
7
- data.tar.gz: 4e2626ca6af897a3a5455c0fad39ae41e19150995dc5f79c8ddcc27664306d86ddb386a4286f63a9f7d699c09ba1cd2b545f12644635d0200647d842b2b9d1e2
6
+ metadata.gz: 94e3ad87a3386023739207107c71b6f0356692a3222f8c048079026f277b134b67f636d7a31c22c328527474a49902c0e36457a0bc9ad20eebbd071f5778ee8a
7
+ data.tar.gz: b7d0d3b26ef8c3914c1ff43598c39589165154baae42dc341e4034d0be66ec0db613927754fd2d692fca99876d59c524f10e4bcc7dadc2f0928d38cc5aaac9e7
@@ -76,7 +76,7 @@ class Ridgepole::Diff
76
76
  table_delta = {}
77
77
 
78
78
  scan_options_change(table_name, from[:options], to[:options], table_delta)
79
- scan_definition_change(from[:definition], to[:definition], from[:indices], table_delta)
79
+ scan_definition_change(from[:definition], to[:definition], from[:indices], from[:options], table_delta)
80
80
  scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta, from[:options], to[:options])
81
81
  scan_foreign_keys_change(from[:foreign_keys], to[:foreign_keys], table_delta, @options)
82
82
 
@@ -92,7 +92,7 @@ class Ridgepole::Diff
92
92
  end
93
93
  end
94
94
 
95
- def scan_definition_change(from, to, from_indices, table_delta)
95
+ def scan_definition_change(from, to, from_indices, table_options, table_delta)
96
96
  from = (from || {}).dup
97
97
  to = (to || {}).dup
98
98
  definition_delta = {}
@@ -101,7 +101,11 @@ class Ridgepole::Diff
101
101
  # for reverse option
102
102
  scan_column_rename(to, from, definition_delta)
103
103
 
104
- priv_column_name = nil
104
+ if table_options[:primary_key].nil?
105
+ priv_column_name = (table_options[:id] == false) ? nil : 'id'
106
+ else
107
+ priv_column_name = table_options[:primary_key]
108
+ end
105
109
 
106
110
  to.each do |column_name, to_attrs|
107
111
  if (from_attrs = from.delete(column_name))
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.6.1.beta'
2
+ VERSION = '0.6.1.beta2'
3
3
  end
@@ -0,0 +1,241 @@
1
+ unless postgresql?
2
+ describe 'Ridgepole::Client#diff -> migrate' do
3
+ context 'when add column after id (pk: normal)' do
4
+ let(:actual_dsl) {
5
+ <<-RUBY
6
+ create_table "employees", force: :cascade do |t|
7
+ t.date "birth_date", null: false
8
+ t.string "first_name", limit: 14, null: false
9
+ t.string "last_name", limit: 16, null: false
10
+ t.string "gender", limit: 1, null: false
11
+ t.date "hire_date", null: false
12
+ t.datetime "created_at", null: false
13
+ t.datetime "updated_at", null: false
14
+ t.binary "registered_name", limit: 65535
15
+ end
16
+ RUBY
17
+ }
18
+
19
+ let(:expected_dsl) {
20
+ <<-RUBY
21
+ create_table "employees", force: :cascade do |t|
22
+ t.string "ext_column", limit: 255, null: false
23
+ t.date "birth_date", null: false
24
+ t.string "first_name", limit: 14, null: false
25
+ t.string "last_name", limit: 16, null: false
26
+ t.string "gender", limit: 1, null: false
27
+ t.date "hire_date", null: false
28
+ t.datetime "created_at", null: false
29
+ t.datetime "updated_at", null: false
30
+ t.binary "registered_name", limit: 255
31
+ end
32
+ RUBY
33
+ }
34
+
35
+ before { subject.diff(actual_dsl).migrate }
36
+ subject { client }
37
+
38
+ it {
39
+ delta = subject.diff(expected_dsl)
40
+ expect(delta.differ?).to be_truthy
41
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
42
+ delta.migrate
43
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
44
+
45
+ expect(show_create_table_mysql('employees')).to eq <<-EOS.strip_heredoc.strip
46
+ CREATE TABLE `employees` (
47
+ `id` int(11) NOT NULL AUTO_INCREMENT,
48
+ `ext_column` varchar(255) NOT NULL,
49
+ `birth_date` date NOT NULL,
50
+ `first_name` varchar(14) NOT NULL,
51
+ `last_name` varchar(16) NOT NULL,
52
+ `gender` varchar(1) NOT NULL,
53
+ `hire_date` date NOT NULL,
54
+ `created_at` datetime NOT NULL,
55
+ `updated_at` datetime NOT NULL,
56
+ `registered_name` varbinary(255) DEFAULT NULL,
57
+ PRIMARY KEY (`id`)
58
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
59
+ EOS
60
+ }
61
+ end
62
+
63
+ context 'when add column after id (pk: emp_id)' do
64
+ let(:actual_dsl) {
65
+ <<-RUBY
66
+ create_table "employees", primary_key: "emp_id", force: :cascade do |t|
67
+ t.date "birth_date", null: false
68
+ t.string "first_name", limit: 14, null: false
69
+ t.string "last_name", limit: 16, null: false
70
+ t.string "gender", limit: 1, null: false
71
+ t.date "hire_date", null: false
72
+ t.datetime "created_at", null: false
73
+ t.datetime "updated_at", null: false
74
+ t.binary "registered_name", limit: 65535
75
+ end
76
+ RUBY
77
+ }
78
+
79
+ let(:expected_dsl) {
80
+ <<-RUBY
81
+ create_table "employees", primary_key: "emp_id", force: :cascade do |t|
82
+ t.string "ext_column", limit: 255, null: false
83
+ t.date "birth_date", null: false
84
+ t.string "first_name", limit: 14, null: false
85
+ t.string "last_name", limit: 16, null: false
86
+ t.string "gender", limit: 1, null: false
87
+ t.date "hire_date", null: false
88
+ t.datetime "created_at", null: false
89
+ t.datetime "updated_at", null: false
90
+ t.binary "registered_name", limit: 255
91
+ end
92
+ RUBY
93
+ }
94
+
95
+ before { subject.diff(actual_dsl).migrate }
96
+ subject { client }
97
+
98
+ it {
99
+ delta = subject.diff(expected_dsl)
100
+ expect(delta.differ?).to be_truthy
101
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
102
+ delta.migrate
103
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
104
+
105
+ expect(show_create_table_mysql('employees')).to eq <<-EOS.strip_heredoc.strip
106
+ CREATE TABLE `employees` (
107
+ `emp_id` int(11) NOT NULL AUTO_INCREMENT,
108
+ `ext_column` varchar(255) NOT NULL,
109
+ `birth_date` date NOT NULL,
110
+ `first_name` varchar(14) NOT NULL,
111
+ `last_name` varchar(16) NOT NULL,
112
+ `gender` varchar(1) NOT NULL,
113
+ `hire_date` date NOT NULL,
114
+ `created_at` datetime NOT NULL,
115
+ `updated_at` datetime NOT NULL,
116
+ `registered_name` varbinary(255) DEFAULT NULL,
117
+ PRIMARY KEY (`emp_id`)
118
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
119
+ EOS
120
+ }
121
+ end
122
+
123
+ context 'when add column after id (pk: no pk)' do
124
+ let(:actual_dsl) {
125
+ <<-RUBY
126
+ create_table "employees", id: false, force: :cascade do |t|
127
+ t.date "birth_date", null: false
128
+ t.string "first_name", limit: 14, null: false
129
+ t.string "last_name", limit: 16, null: false
130
+ t.string "gender", limit: 1, null: false
131
+ t.date "hire_date", null: false
132
+ t.datetime "created_at", null: false
133
+ t.datetime "updated_at", null: false
134
+ t.binary "registered_name", limit: 65535
135
+ end
136
+ RUBY
137
+ }
138
+
139
+ let(:expected_dsl) {
140
+ <<-RUBY
141
+ create_table "employees", id: false, force: :cascade do |t|
142
+ t.string "ext_column", limit: 255, null: false
143
+ t.date "birth_date", null: false
144
+ t.string "first_name", limit: 14, null: false
145
+ t.string "last_name", limit: 16, null: false
146
+ t.string "gender", limit: 1, null: false
147
+ t.date "hire_date", null: false
148
+ t.datetime "created_at", null: false
149
+ t.datetime "updated_at", null: false
150
+ t.binary "registered_name", limit: 255
151
+ end
152
+ RUBY
153
+ }
154
+
155
+ before { subject.diff(actual_dsl).migrate }
156
+ subject { client }
157
+
158
+ it {
159
+ delta = subject.diff(expected_dsl)
160
+ expect(delta.differ?).to be_truthy
161
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
162
+ delta.migrate
163
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
164
+
165
+ expect(show_create_table_mysql('employees')).to eq <<-EOS.strip_heredoc.strip
166
+ CREATE TABLE `employees` (
167
+ `ext_column` varchar(255) NOT NULL,
168
+ `birth_date` date NOT NULL,
169
+ `first_name` varchar(14) NOT NULL,
170
+ `last_name` varchar(16) NOT NULL,
171
+ `gender` varchar(1) NOT NULL,
172
+ `hire_date` date NOT NULL,
173
+ `created_at` datetime NOT NULL,
174
+ `updated_at` datetime NOT NULL,
175
+ `registered_name` varbinary(255) DEFAULT NULL
176
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
177
+ EOS
178
+ }
179
+ end
180
+
181
+ context 'when add column after id (pk: with pk delta)' do
182
+ let(:actual_dsl) {
183
+ <<-RUBY
184
+ create_table "employees", force: :cascade do |t|
185
+ t.date "birth_date", null: false
186
+ t.string "first_name", limit: 14, null: false
187
+ t.string "last_name", limit: 16, null: false
188
+ t.string "gender", limit: 1, null: false
189
+ t.date "hire_date", null: false
190
+ t.datetime "created_at", null: false
191
+ t.datetime "updated_at", null: false
192
+ t.binary "registered_name", limit: 65535
193
+ end
194
+ RUBY
195
+ }
196
+
197
+ let(:expected_dsl) {
198
+ <<-RUBY
199
+ create_table "employees", primary_key: "emp_id", force: :cascade do |t|
200
+ t.string "ext_column", limit: 255, null: false
201
+ t.date "birth_date", null: false
202
+ t.string "first_name", limit: 14, null: false
203
+ t.string "last_name", limit: 16, null: false
204
+ t.string "gender", limit: 1, null: false
205
+ t.date "hire_date", null: false
206
+ t.datetime "created_at", null: false
207
+ t.datetime "updated_at", null: false
208
+ t.binary "registered_name", limit: 255
209
+ end
210
+ RUBY
211
+ }
212
+
213
+ before { subject.diff(actual_dsl).migrate }
214
+ subject { client }
215
+
216
+ it {
217
+ delta = subject.diff(expected_dsl)
218
+ expect(delta.differ?).to be_truthy
219
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
220
+ delta.migrate
221
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.sub(', primary_key: "emp_id"', '')
222
+
223
+ expect(show_create_table_mysql('employees')).to eq <<-EOS.strip_heredoc.strip
224
+ CREATE TABLE `employees` (
225
+ `id` int(11) NOT NULL AUTO_INCREMENT,
226
+ `ext_column` varchar(255) NOT NULL,
227
+ `birth_date` date NOT NULL,
228
+ `first_name` varchar(14) NOT NULL,
229
+ `last_name` varchar(16) NOT NULL,
230
+ `gender` varchar(1) NOT NULL,
231
+ `hire_date` date NOT NULL,
232
+ `created_at` datetime NOT NULL,
233
+ `updated_at` datetime NOT NULL,
234
+ `registered_name` varbinary(255) DEFAULT NULL,
235
+ PRIMARY KEY (`id`)
236
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
237
+ EOS
238
+ }
239
+ end
240
+ end
241
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1.beta
4
+ version: 0.6.1.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-09 00:00:00.000000000 Z
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -173,6 +173,7 @@ files:
173
173
  - spec/mysql/migrate/migrate_change_column3_spec.rb
174
174
  - spec/mysql/migrate/migrate_change_column4_spec.rb
175
175
  - spec/mysql/migrate/migrate_change_column5_spec.rb
176
+ - spec/mysql/migrate/migrate_change_column6_spec.rb
176
177
  - spec/mysql/migrate/migrate_change_column_float_spec.rb
177
178
  - spec/mysql/migrate/migrate_change_column_spec.rb
178
179
  - spec/mysql/migrate/migrate_change_index2_spec.rb
@@ -273,6 +274,7 @@ test_files:
273
274
  - spec/mysql/migrate/migrate_change_column3_spec.rb
274
275
  - spec/mysql/migrate/migrate_change_column4_spec.rb
275
276
  - spec/mysql/migrate/migrate_change_column5_spec.rb
277
+ - spec/mysql/migrate/migrate_change_column6_spec.rb
276
278
  - spec/mysql/migrate/migrate_change_column_float_spec.rb
277
279
  - spec/mysql/migrate/migrate_change_column_spec.rb
278
280
  - spec/mysql/migrate/migrate_change_index2_spec.rb