ridgepole 0.4.1 → 0.4.2

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: 74af55adebfffcd9880e5a0fde3e2eee3fc2c75d
4
- data.tar.gz: 1b3255a9a2c1b29b3980b32739a55b83100542c3
3
+ metadata.gz: a09898d122a3138706ad9e835a0e0941a56749be
4
+ data.tar.gz: e0bd6aa6ba825488ef7e53fcd68db3267dcde79a
5
5
  SHA512:
6
- metadata.gz: 83ae32148265a558bb781c2eadf4cc3b988d2a4380fb66be2e7e13163b239e7ea1c3d1a4136f3d7149ede683338dc0fb2b0e8ced5c8d3b460fd4d9647bb10fe0
7
- data.tar.gz: 9099196ec666a10f7da892c3af21302e654c0801516815e1a888eec86a034d649cfe4eb940cd8ffafa0cd457c08b63657a1cf05621a57793ee78773143a31a42
6
+ metadata.gz: ecf91300412d185e49794b4a894180d70747783b88a641856d3af20e35b668aa24201c4a5188cbeb68e2f1c83177dccf19eddafb66a4ad61f807e5f688ac569c
7
+ data.tar.gz: 9f83de31e8549e7956b79b0c3033208354a4e823901384406ca171295f33a5ea98f8c9f4f224af917a4854ae395d05a6112d81b00aac3267b88ac6266f41bfff
data/README.md CHANGED
@@ -32,6 +32,7 @@ Usage: ridgepole [options]
32
32
  --dry-run
33
33
  --table-options OPTIONS
34
34
  --bulk-change
35
+ --default-int-limit LIMIT
35
36
  --pre-query QUERY
36
37
  --post-query QUERY
37
38
  -e, --export
data/bin/ridgepole CHANGED
@@ -51,6 +51,9 @@ ARGV.options do |opt|
51
51
  raise "Cannot use `bulk-change` in `merge`" if options[:merge]
52
52
  options[:bulk_change] = true
53
53
  }
54
+ opt.on('', '--default-int-limit LIMIT', Integer) {|v|
55
+ options[:default_int_limit] = v
56
+ }
54
57
  opt.on('', '--pre-query QUERY') {|v| options[:pre_query] = v }
55
58
  opt.on('', '--post-query QUERY') {|v| options[:post_query] = v }
56
59
  opt.on('-e', '--export') { set_mode[:export] }
@@ -153,6 +153,10 @@ create_table(#{table_name.inspect}, #{options.inspect}) do |t|
153
153
  column_type = column_attrs.fetch(:type)
154
154
  column_options = column_attrs[:options] || {}
155
155
 
156
+ if @options[:default_int_limit] and column_type == :integer
157
+ column_options[:limit] ||= @options[:default_int_limit]
158
+ end
159
+
156
160
  buf.puts(<<-EOS)
157
161
  t.#{column_type}(#{column_name.inspect}, #{column_options.inspect})
158
162
  EOS
@@ -226,6 +230,10 @@ drop_table(#{table_name.inspect})
226
230
  type = attrs.fetch(:type)
227
231
  options = attrs[:options] || {}
228
232
 
233
+ if @options[:default_int_limit] and type == :integer
234
+ options[:limit] ||= @options[:default_int_limit]
235
+ end
236
+
229
237
  if @options[:bulk_change]
230
238
  buf.puts(<<-EOS)
231
239
  t.column(#{column_name.inspect}, #{type.inspect}, #{options.inspect})
@@ -37,6 +37,22 @@ class Ridgepole::DSLParser
37
37
  column_names.each {|name| column(name, column_type, options) }
38
38
  end
39
39
  end
40
+
41
+ def timestamps(*args)
42
+ options = { :null => false }.merge(args.extract_options!)
43
+ column(:created_at, :datetime, options.dup)
44
+ column(:updated_at, :datetime, options.dup)
45
+ end
46
+
47
+ def references(*args)
48
+ options = args.extract_options!
49
+ polymorphic = options.delete(:polymorphic)
50
+ args.each do |col|
51
+ column("#{col}_id", :integer, options.dup)
52
+ column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options.dup) unless polymorphic.nil?
53
+ end
54
+ end
55
+ alias :belongs_to :references
40
56
  end
41
57
 
42
58
  attr_reader :__definition
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
data/ridgepole.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'activerecord'
22
- spec.add_dependency 'activerecord-mysql-unsigned', '~> 0.1.3'
22
+ spec.add_dependency 'activerecord-mysql-unsigned', '>= 0.2.0'
23
23
  spec.add_development_dependency 'bundler'
24
24
  spec.add_development_dependency 'rake'
25
25
  spec.add_development_dependency 'rspec', '>= 3.0.0'
@@ -0,0 +1,118 @@
1
+ describe 'Ridgepole::Client#diff -> migrate' do
2
+ context 'when add column (int/noop) (1)' do
3
+ let(:actual_dsl) {
4
+ <<-RUBY
5
+ create_table "dept_emp", id: false, force: true do |t|
6
+ t.integer "emp_no", null: false
7
+ t.string "dept_no", limit: 4, null: false
8
+ t.date "from_date", null: false
9
+ t.date "to_date", null: false
10
+ end
11
+ RUBY
12
+ }
13
+
14
+ let(:expected_dsl) {
15
+ <<-RUBY
16
+ create_table "dept_emp", id: false, force: true do |t|
17
+ t.integer "emp_no", null: false
18
+ t.integer "emp_no2", null: false
19
+ t.string "dept_no", limit: 4, null: false
20
+ t.date "from_date", null: false
21
+ t.date "to_date", null: false
22
+ end
23
+ RUBY
24
+ }
25
+
26
+ before { subject.diff(actual_dsl).migrate }
27
+ subject { client }
28
+
29
+ it {
30
+ delta = subject.diff(expected_dsl)
31
+ expect(delta.differ?).to be_truthy
32
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
33
+ sql = delta.migrate(:noop => true)
34
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
35
+
36
+ sql = sql.each_line.map {|i| i.strip }.join("\n")
37
+ expect(sql).to eq("ALTER TABLE `dept_emp` ADD `emp_no2` int(4) NOT NULL AFTER `emp_no`")
38
+ }
39
+ end
40
+
41
+ context 'when add column (int/noop) (2)' do
42
+ let(:actual_dsl) {
43
+ <<-RUBY
44
+ create_table "dept_emp", id: false, force: true do |t|
45
+ t.integer "emp_no", null: false
46
+ t.string "dept_no", limit: 4, null: false
47
+ t.date "from_date", null: false
48
+ t.date "to_date", null: false
49
+ end
50
+ RUBY
51
+ }
52
+
53
+ let(:expected_dsl) {
54
+ <<-RUBY
55
+ create_table "dept_emp", id: false, force: true do |t|
56
+ t.integer "emp_no", null: false
57
+ t.integer "emp_no2", null: false
58
+ t.string "dept_no", limit: 4, null: false
59
+ t.date "from_date", null: false
60
+ t.date "to_date", null: false
61
+ end
62
+ RUBY
63
+ }
64
+
65
+ before { subject.diff(actual_dsl).migrate }
66
+ subject { client(:default_int_limit => 11) }
67
+
68
+ it {
69
+ delta = subject.diff(expected_dsl)
70
+ expect(delta.differ?).to be_truthy
71
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
72
+ sql = delta.migrate(:noop => true)
73
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
74
+
75
+ sql = sql.each_line.map {|i| i.strip }.join("\n")
76
+ expect(sql).to eq("ALTER TABLE `dept_emp` ADD `emp_no2` int(11) NOT NULL AFTER `emp_no`")
77
+ }
78
+ end
79
+
80
+ context 'when add column (int/noop) (3)' do
81
+ let(:actual_dsl) {
82
+ <<-RUBY
83
+ create_table "dept_emp", id: false, force: true do |t|
84
+ t.integer "emp_no", null: false
85
+ t.string "dept_no", limit: 4, null: false
86
+ t.date "from_date", null: false
87
+ t.date "to_date", null: false
88
+ end
89
+ RUBY
90
+ }
91
+
92
+ let(:expected_dsl) {
93
+ <<-RUBY
94
+ create_table "dept_emp", id: false, force: true do |t|
95
+ t.integer "emp_no", null: false
96
+ t.integer "emp_no2", limit: 4, null: false
97
+ t.string "dept_no", limit: 4, null: false
98
+ t.date "from_date", null: false
99
+ t.date "to_date", null: false
100
+ end
101
+ RUBY
102
+ }
103
+
104
+ before { subject.diff(actual_dsl).migrate }
105
+ subject { client(:default_int_limit => 11) }
106
+
107
+ it {
108
+ delta = subject.diff(expected_dsl)
109
+ expect(delta.differ?).to be_truthy
110
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
111
+ sql = delta.migrate(:noop => true)
112
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
113
+
114
+ sql = sql.each_line.map {|i| i.strip }.join("\n")
115
+ expect(sql).to eq("ALTER TABLE `dept_emp` ADD `emp_no2` int(4) NOT NULL AFTER `emp_no`")
116
+ }
117
+ end
118
+ end
@@ -0,0 +1,272 @@
1
+ describe 'Ridgepole::Client#diff -> migrate' do
2
+ context 'when use timestamps (no change)' do
3
+ let(:actual_dsl) {
4
+ <<-RUBY
5
+ create_table "employees", primary_key: "emp_no", force: true do |t|
6
+ t.date "birth_date", null: false
7
+ t.string "first_name", limit: 14, null: false
8
+ t.string "last_name", limit: 16, null: false
9
+ t.string "gender", limit: 1, null: false
10
+ t.date "hire_date", null: false
11
+ t.datetime "created_at", null: false
12
+ t.datetime "updated_at", null: false
13
+ end
14
+ RUBY
15
+ }
16
+
17
+ let(:expected_dsl) {
18
+ <<-RUBY
19
+ create_table "employees", primary_key: "emp_no", force: true do |t|
20
+ t.date "birth_date", null: false
21
+ t.string "first_name", limit: 14, null: false
22
+ t.string "last_name", limit: 16, null: false
23
+ t.string "gender", limit: 1, null: false
24
+ t.date "hire_date", null: false
25
+ t.timestamps
26
+ end
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_falsey
36
+ }
37
+ end
38
+
39
+ context 'when use timestamps (change)' do
40
+ let(:actual_dsl) {
41
+ <<-RUBY
42
+ create_table "employees", primary_key: "emp_no", force: true do |t|
43
+ t.date "birth_date", null: false
44
+ t.string "first_name", limit: 14, 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
48
+ end
49
+ RUBY
50
+ }
51
+
52
+ let(:dsl) {
53
+ <<-RUBY
54
+ create_table "employees", primary_key: "emp_no", force: true do |t|
55
+ t.date "birth_date", null: false
56
+ t.string "first_name", limit: 14, null: false
57
+ t.string "last_name", limit: 16, null: false
58
+ t.string "gender", limit: 1, null: false
59
+ t.date "hire_date", null: false
60
+ t.timestamps
61
+ end
62
+ RUBY
63
+ }
64
+
65
+ let(:expected_dsl) {
66
+ <<-RUBY
67
+ create_table "employees", primary_key: "emp_no", force: true do |t|
68
+ t.date "birth_date", null: false
69
+ t.string "first_name", limit: 14, null: false
70
+ t.string "last_name", limit: 16, null: false
71
+ t.string "gender", limit: 1, null: false
72
+ t.date "hire_date", null: false
73
+ t.datetime "created_at", null: false
74
+ t.datetime "updated_at", null: false
75
+ end
76
+ RUBY
77
+ }
78
+
79
+ before { subject.diff(actual_dsl).migrate }
80
+ subject { client }
81
+
82
+ it {
83
+ delta = subject.diff(dsl)
84
+ expect(delta.differ?).to be_truthy
85
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
86
+ delta.migrate
87
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/(\s*,\s*unsigned: false)?\s*,\s*null: true/, '')
88
+ }
89
+ end
90
+
91
+ context 'when use references (no change)' do
92
+ let(:actual_dsl) {
93
+ <<-RUBY
94
+ create_table "employees", primary_key: "emp_no", force: true do |t|
95
+ t.date "birth_date", null: false
96
+ t.string "first_name", limit: 14, null: false
97
+ t.string "last_name", limit: 16, null: false
98
+ t.string "gender", limit: 1, null: false
99
+ t.date "hire_date", null: false
100
+ t.integer "products_id"
101
+ t.integer "user_id"
102
+ end
103
+ RUBY
104
+ }
105
+
106
+ let(:expected_dsl) {
107
+ <<-RUBY
108
+ create_table "employees", primary_key: "emp_no", force: true do |t|
109
+ t.date "birth_date", null: false
110
+ t.string "first_name", limit: 14, null: false
111
+ t.string "last_name", limit: 16, null: false
112
+ t.string "gender", limit: 1, null: false
113
+ t.date "hire_date", null: false
114
+ t.references :products, :user
115
+ end
116
+ RUBY
117
+ }
118
+
119
+ before { subject.diff(actual_dsl).migrate }
120
+ subject { client }
121
+
122
+ it {
123
+ delta = subject.diff(expected_dsl)
124
+ expect(delta.differ?).to be_falsey
125
+ }
126
+ end
127
+
128
+ context 'when use references with polymorphic (no change)' do
129
+ let(:actual_dsl) {
130
+ <<-RUBY
131
+ create_table "employees", primary_key: "emp_no", force: true do |t|
132
+ t.date "birth_date", null: false
133
+ t.string "first_name", limit: 14, null: false
134
+ t.string "last_name", limit: 16, null: false
135
+ t.string "gender", limit: 1, null: false
136
+ t.date "hire_date", null: false
137
+ t.integer "products_id"
138
+ t.string "products_type"
139
+ t.integer "user_id"
140
+ t.string "user_type"
141
+ end
142
+ RUBY
143
+ }
144
+
145
+ let(:expected_dsl) {
146
+ <<-RUBY
147
+ create_table "employees", primary_key: "emp_no", force: true do |t|
148
+ t.date "birth_date", null: false
149
+ t.string "first_name", limit: 14, null: false
150
+ t.string "last_name", limit: 16, null: false
151
+ t.string "gender", limit: 1, null: false
152
+ t.date "hire_date", null: false
153
+ t.references :products, :user, polymorphic: true
154
+ end
155
+ RUBY
156
+ }
157
+
158
+ before { subject.diff(actual_dsl).migrate }
159
+ subject { client }
160
+
161
+ it {
162
+ delta = subject.diff(expected_dsl)
163
+ expect(delta.differ?).to be_falsey
164
+ }
165
+ end
166
+
167
+ context 'when use references (change)' do
168
+ let(:actual_dsl) {
169
+ <<-RUBY
170
+ create_table "employees", primary_key: "emp_no", force: true do |t|
171
+ t.date "birth_date", null: false
172
+ t.string "first_name", limit: 14, null: false
173
+ t.string "last_name", limit: 16, null: false
174
+ t.string "gender", limit: 1, null: false
175
+ t.date "hire_date", null: false
176
+ end
177
+ RUBY
178
+ }
179
+
180
+ let(:dsl) {
181
+ <<-RUBY
182
+ create_table "employees", primary_key: "emp_no", force: true do |t|
183
+ t.date "birth_date", null: false
184
+ t.string "first_name", limit: 14, null: false
185
+ t.string "last_name", limit: 16, null: false
186
+ t.string "gender", limit: 1, null: false
187
+ t.date "hire_date", null: false
188
+ t.references :products, :user
189
+ end
190
+ RUBY
191
+ }
192
+
193
+ let(:expected_dsl) {
194
+ <<-RUBY
195
+ create_table "employees", primary_key: "emp_no", force: true do |t|
196
+ t.date "birth_date", null: false
197
+ t.string "first_name", limit: 14, null: false
198
+ t.string "last_name", limit: 16, null: false
199
+ t.string "gender", limit: 1, null: false
200
+ t.date "hire_date", null: false
201
+ t.integer "products_id"
202
+ t.integer "user_id"
203
+ end
204
+ RUBY
205
+ }
206
+
207
+ before { subject.diff(actual_dsl).migrate }
208
+ subject { client }
209
+
210
+ it {
211
+ delta = subject.diff(dsl)
212
+ expect(delta.differ?).to be_truthy
213
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
214
+ delta.migrate
215
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/(\s*,\s*unsigned: false)?\s*,\s*null: true/, '')
216
+ }
217
+ end
218
+
219
+ context 'when use references with polymorphic (change)' do
220
+ let(:actual_dsl) {
221
+ <<-RUBY
222
+ create_table "employees", primary_key: "emp_no", force: true do |t|
223
+ t.date "birth_date", null: false
224
+ t.string "first_name", limit: 14, null: false
225
+ t.string "last_name", limit: 16, null: false
226
+ t.string "gender", limit: 1, null: false
227
+ t.date "hire_date", null: false
228
+ end
229
+ RUBY
230
+ }
231
+
232
+ let(:dsl) {
233
+ <<-RUBY
234
+ create_table "employees", primary_key: "emp_no", force: true do |t|
235
+ t.date "birth_date", null: false
236
+ t.string "first_name", limit: 14, null: false
237
+ t.string "last_name", limit: 16, null: false
238
+ t.string "gender", limit: 1, null: false
239
+ t.date "hire_date", null: false
240
+ t.references :products, :user, polymorphic: true
241
+ end
242
+ RUBY
243
+ }
244
+
245
+ let(:expected_dsl) {
246
+ <<-RUBY
247
+ create_table "employees", primary_key: "emp_no", force: true do |t|
248
+ t.date "birth_date", null: false
249
+ t.string "first_name", limit: 14, null: false
250
+ t.string "last_name", limit: 16, null: false
251
+ t.string "gender", limit: 1, null: false
252
+ t.date "hire_date", null: false
253
+ t.integer "products_id"
254
+ t.string "products_type"
255
+ t.integer "user_id"
256
+ t.string "user_type"
257
+ end
258
+ RUBY
259
+ }
260
+
261
+ before { subject.diff(actual_dsl).migrate }
262
+ subject { client }
263
+
264
+ it {
265
+ delta = subject.diff(dsl)
266
+ expect(delta.differ?).to be_truthy
267
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
268
+ delta.migrate
269
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/(\s*,\s*unsigned: false)?\s*,\s*null: true/, '')
270
+ }
271
+ end
272
+ end
@@ -85,18 +85,18 @@ describe 'Ridgepole::Client#diff -> migrate' do
85
85
  CREATE UNIQUE INDEX `idx_name` USING btree ON `clubs` (`name`)
86
86
  CREATE TABLE `departments` (`dept_no` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
87
87
  CREATE UNIQUE INDEX `dept_name` USING btree ON `departments` (`dept_name`)
88
- CREATE TABLE `dept_emp` (`emp_no` int(10) NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
88
+ CREATE TABLE `dept_emp` (`emp_no` int(4) NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
89
89
  CREATE INDEX `dept_no` USING btree ON `dept_emp` (`dept_no`)
90
90
  CREATE INDEX `emp_no` USING btree ON `dept_emp` (`emp_no`)
91
- CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int(10) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
91
+ CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
92
92
  CREATE INDEX `dept_no` USING btree ON `dept_manager` (`dept_no`)
93
93
  CREATE INDEX `emp_no` USING btree ON `dept_manager` (`emp_no`)
94
94
  CREATE TABLE `employee_clubs` (`id` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `emp_no` int(10) unsigned NOT NULL, `club_id` int(10) unsigned NOT NULL) ENGINE=InnoDB
95
95
  CREATE INDEX `idx_emp_no_club_id` USING btree ON `employee_clubs` (`emp_no`, `club_id`)
96
96
  CREATE TABLE `employees` (`emp_no` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `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
97
- CREATE TABLE `salaries` (`emp_no` int(10) NOT NULL, `salary` int(10) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
97
+ CREATE TABLE `salaries` (`emp_no` int(4) NOT NULL, `salary` int(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
98
98
  CREATE INDEX `emp_no` USING btree ON `salaries` (`emp_no`)
99
- CREATE TABLE `titles` (`emp_no` int(10) NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
99
+ CREATE TABLE `titles` (`emp_no` int(4) NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
100
100
  CREATE INDEX `emp_no` USING btree ON `titles` (`emp_no`)
101
101
  SQL
102
102
  }
@@ -114,18 +114,121 @@ describe 'Ridgepole::Client#diff -> migrate' do
114
114
  ALTER TABLE `clubs` ADD UNIQUE INDEX idx_name (`name`)
115
115
  CREATE TABLE `departments` (`dept_no` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
116
116
  ALTER TABLE `departments` ADD UNIQUE INDEX dept_name (`dept_name`)
117
- CREATE TABLE `dept_emp` (`emp_no` int(10) NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
117
+ CREATE TABLE `dept_emp` (`emp_no` int(4) NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
118
118
  ALTER TABLE `dept_emp` ADD INDEX dept_no (`dept_no`), ADD INDEX emp_no (`emp_no`)
119
- CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int(10) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
119
+ CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
120
120
  ALTER TABLE `dept_manager` ADD INDEX dept_no (`dept_no`), ADD INDEX emp_no (`emp_no`)
121
121
  CREATE TABLE `employee_clubs` (`id` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `emp_no` int(10) unsigned NOT NULL, `club_id` int(10) unsigned NOT NULL) ENGINE=InnoDB
122
122
  ALTER TABLE `employee_clubs` ADD INDEX idx_emp_no_club_id (`emp_no`, `club_id`)
123
123
  CREATE TABLE `employees` (`emp_no` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `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
124
- CREATE TABLE `salaries` (`emp_no` int(10) NOT NULL, `salary` int(10) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
124
+ CREATE TABLE `salaries` (`emp_no` int(4) NOT NULL, `salary` int(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
125
125
  ALTER TABLE `salaries` ADD INDEX emp_no (`emp_no`)
126
- CREATE TABLE `titles` (`emp_no` int(10) NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
126
+ CREATE TABLE `titles` (`emp_no` int(4) NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
127
127
  ALTER TABLE `titles` ADD INDEX emp_no (`emp_no`)
128
128
  SQL
129
129
  }
130
130
  end
131
+
132
+ context 'when no operation' do
133
+ let(:actual_dsl) { '' }
134
+ let(:expected_dsl) {
135
+ <<-RUBY
136
+ create_table "clubs", force: true do |t|
137
+ t.string "name", default: "", null: false
138
+ end
139
+
140
+ add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
141
+
142
+ create_table "departments", primary_key: "dept_no", force: true do |t|
143
+ t.string "dept_name", limit: 40, null: false
144
+ end
145
+
146
+ add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
147
+
148
+ create_table "dept_emp", id: false, force: true do |t|
149
+ t.integer "emp_no", null: false
150
+ t.string "dept_no", limit: 4, null: false
151
+ t.date "from_date", null: false
152
+ t.date "to_date", null: false
153
+ end
154
+
155
+ add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
156
+ add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
157
+
158
+ create_table "dept_manager", id: false, force: true do |t|
159
+ t.string "dept_no", limit: 4, null: false
160
+ t.integer "emp_no", limit: 4, null: false
161
+ t.date "from_date", null: false
162
+ t.date "to_date", null: false
163
+ end
164
+
165
+ add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
166
+ add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
167
+
168
+ create_table "employee_clubs", force: true do |t|
169
+ t.integer "emp_no", unsigned: true, null: false
170
+ t.integer "club_id", unsigned: true, null: false
171
+ end
172
+
173
+ add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
174
+
175
+ create_table "employees", primary_key: "emp_no", force: true do |t|
176
+ t.date "birth_date", null: false
177
+ t.string "first_name", limit: 14, null: false
178
+ t.string "last_name", limit: 16, null: false
179
+ t.string "gender", limit: 1, null: false
180
+ t.date "hire_date", null: false
181
+ end
182
+
183
+ create_table "salaries", id: false, force: true do |t|
184
+ t.integer "emp_no", null: false
185
+ t.integer "salary", null: false
186
+ t.date "from_date", null: false
187
+ t.date "to_date", null: false
188
+ end
189
+
190
+ add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
191
+
192
+ create_table "titles", id: false, force: true do |t|
193
+ t.integer "emp_no", null: false
194
+ t.string "title", limit: 50, null: false
195
+ t.date "from_date", null: false
196
+ t.date "to_date"
197
+ end
198
+
199
+ add_index "titles", ["emp_no"], name: "emp_no", using: :btree
200
+ RUBY
201
+ }
202
+
203
+ subject { client(:default_int_limit => 11) }
204
+
205
+ it {
206
+ delta = subject.diff(expected_dsl)
207
+ expect(delta.differ?).to be_truthy
208
+ sql = delta.migrate(:noop => true)
209
+ expect(subject.dump).to eq actual_dsl
210
+
211
+ sql = sql.each_line.map {|i| i.strip }.join("\n")
212
+
213
+ expect(sql).to eq <<-SQL.strip_heredoc.strip
214
+ CREATE TABLE `clubs` (`id` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
215
+ CREATE UNIQUE INDEX `idx_name` USING btree ON `clubs` (`name`)
216
+ CREATE TABLE `departments` (`dept_no` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
217
+ CREATE UNIQUE INDEX `dept_name` USING btree ON `departments` (`dept_name`)
218
+ CREATE TABLE `dept_emp` (`emp_no` int(11) NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
219
+ CREATE INDEX `dept_no` USING btree ON `dept_emp` (`dept_no`)
220
+ CREATE INDEX `emp_no` USING btree ON `dept_emp` (`emp_no`)
221
+ CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
222
+ CREATE INDEX `dept_no` USING btree ON `dept_manager` (`dept_no`)
223
+ CREATE INDEX `emp_no` USING btree ON `dept_manager` (`emp_no`)
224
+ CREATE TABLE `employee_clubs` (`id` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `emp_no` int(10) unsigned NOT NULL, `club_id` int(10) unsigned NOT NULL) ENGINE=InnoDB
225
+ CREATE INDEX `idx_emp_no_club_id` USING btree ON `employee_clubs` (`emp_no`, `club_id`)
226
+ CREATE TABLE `employees` (`emp_no` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `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
227
+ CREATE TABLE `salaries` (`emp_no` int(11) NOT NULL, `salary` int(11) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
228
+ CREATE INDEX `emp_no` USING btree ON `salaries` (`emp_no`)
229
+ CREATE TABLE `titles` (`emp_no` int(11) NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
230
+ CREATE INDEX `emp_no` USING btree ON `titles` (`emp_no`)
231
+ SQL
232
+ }
233
+ end
131
234
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: activerecord-mysql-unsigned
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.3
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.3
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -129,8 +129,10 @@ files:
129
129
  - spec/dump/dump_some_tables_spec.rb
130
130
  - spec/dump/dump_spec.rb
131
131
  - spec/migrate/check_orphan_index_spec.rb
132
+ - spec/migrate/migrate_add_column2_spec.rb
132
133
  - spec/migrate/migrate_add_column_spec.rb
133
134
  - spec/migrate/migrate_change_column2_spec.rb
135
+ - spec/migrate/migrate_change_column3_spec.rb
134
136
  - spec/migrate/migrate_change_column_spec.rb
135
137
  - spec/migrate/migrate_change_index2_spec.rb
136
138
  - spec/migrate/migrate_change_index_spec.rb
@@ -194,8 +196,10 @@ test_files:
194
196
  - spec/dump/dump_some_tables_spec.rb
195
197
  - spec/dump/dump_spec.rb
196
198
  - spec/migrate/check_orphan_index_spec.rb
199
+ - spec/migrate/migrate_add_column2_spec.rb
197
200
  - spec/migrate/migrate_add_column_spec.rb
198
201
  - spec/migrate/migrate_change_column2_spec.rb
202
+ - spec/migrate/migrate_change_column3_spec.rb
199
203
  - spec/migrate/migrate_change_column_spec.rb
200
204
  - spec/migrate/migrate_change_index2_spec.rb
201
205
  - spec/migrate/migrate_change_index_spec.rb