ridgepole 0.7.0.beta8 → 0.7.0.beta9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6379a32db8dc48969ccf8c184534eccdea98fdd0
4
- data.tar.gz: efbb7beeb7656df70ed62a102585f7ef2bbe17d7
3
+ metadata.gz: 5fad6f6046bff06fbe559b4da0f9bf1f302a5d8d
4
+ data.tar.gz: d74561e4b51b708c04346a2d7cf23fb81b16506c
5
5
  SHA512:
6
- metadata.gz: 0dfbe2a44db029662943ad2f447e4d72a26f9d970807336f0cce0806cf1758337e1f65587cd9ba0b7496887e87ebcd82d0a42cec842fd2443e90bb5b8c4cf63b
7
- data.tar.gz: 4ba605415d1d48c00eb462f9dc6573c1ee131c456eb9cc215f471604b401f11972a4023ee6c14664a2c23a21a274c6b466c9e78564092cc63e034225f2ba54bb
6
+ metadata.gz: ee4042bf17a7f05d6fe062fa57925578e5a22a5cd7a169ddae4048ef328aff2696a90beb1b4ec8e58ea3d74b170aae4ba26d549d81e39143d7fc5b22631fb215
7
+ data.tar.gz: c7af7cb79c2cd5a4659de44f8b8f5a819e89b8ed7d3175eef6ff5ab417532012469b9d743059082e28f099585903602a148c953558c97f38f12d3a53939148b1
data/README.md CHANGED
@@ -9,7 +9,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
9
9
  [![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.6)](https://travis-ci.org/winebarrel/ridgepole)
10
10
  [![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.6)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.6)
11
11
 
12
- [![Edge Version](https://img.shields.io/badge/edge_version-0.7.0.beta8-brightgreen.svg)](https://rubygems.org/gems/ridgepole/versions/0.7.0.beta8)
12
+ [![Edge Version](https://img.shields.io/badge/edge_version-0.7.0.beta9-brightgreen.svg)](https://rubygems.org/gems/ridgepole/versions/0.7.0.beta9)
13
13
  [![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.7)](https://travis-ci.org/winebarrel/ridgepole)
14
14
  [![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.7)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.7)
15
15
 
@@ -467,18 +467,40 @@ class Ridgepole::Diff
467
467
  next unless parent_table_info
468
468
 
469
469
  table_options = parent_table_info.fetch(:options)
470
- pk_type = table_options[:id] || @options[:check_relation_type].to_sym
471
- child_column_type = column_attrs[:type]
472
470
 
473
- if pk_type != child_column_type
471
+ parent_column_info = {
472
+ :type => table_options[:id] || @options[:check_relation_type].to_sym,
473
+ :unsigned => table_options[:unsigned],
474
+ }
475
+
476
+ child_column_info = {
477
+ :type => column_attrs[:type],
478
+ :unsigned => column_attrs.fetch(:options, {})[:unsigned],
479
+ }
480
+
481
+ [parent_column_info, child_column_info].each do |column_info|
482
+ unless column_info[:unsigned]
483
+ column_info.delete(:unsigned)
484
+ end
485
+
486
+ # for PostgreSQL
487
+ column_info[:type] = {
488
+ :serial => :integer,
489
+ :bigserial => :bigint,
490
+ }.fetch(column_info[:type], column_info[:type])
491
+ end
492
+
493
+ if parent_column_info != child_column_info
474
494
  parent_label = "#{parent_table}.id"
475
495
  child_label = "#{child_table}.#{column_name}"
476
496
  label_len = [parent_label.length, child_label.length].max
497
+ parent_column_info_str = parent_column_info.inspect.slice(1...-1)
498
+ child_column_info_str = child_column_info.inspect.slice(1...-1)
477
499
 
478
500
  @logger.warn(<<-EOS % [label_len, parent_label, label_len, child_label])
479
501
  [WARNING] Relation column type is different.
480
- %*s: #{pk_type}
481
- %*s: #{child_column_type}
502
+ %*s: #{parent_column_info_str}
503
+ %*s: #{child_column_info_str}
482
504
  EOS
483
505
  end
484
506
  end
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.7.0.beta8'
2
+ VERSION = '0.7.0.beta9'
3
3
  end
@@ -1,4 +1,4 @@
1
- describe 'Ridgepole::Client#diff -> migrate', 5.1 do
1
+ describe 'Ridgepole::Client#diff -> migrate', condition: 5.1 do
2
2
  context 'with warning' do
3
3
  let(:actual_dsl) {
4
4
  erbh(<<-EOS)
@@ -45,8 +45,66 @@ describe 'Ridgepole::Client#diff -> migrate', 5.1 do
45
45
  it {
46
46
  expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
47
47
  [WARNING] Relation column type is different.
48
- employees.id: bigint
49
- dept_manager.employee_id: integer
48
+ employees.id: :type=>:bigint
49
+ dept_manager.employee_id: :type=>:integer
50
+ EOS
51
+
52
+ delta = subject.diff(expected_dsl)
53
+ expect(delta.differ?).to be_truthy
54
+ expect(subject.dump).to match_fuzzy actual_dsl
55
+ delta.migrate
56
+ expect(subject.dump).to match_fuzzy expected_dsl
57
+ }
58
+ end
59
+
60
+ context 'with unsigned warning' do
61
+ let(:actual_dsl) {
62
+ erbh(<<-EOS)
63
+ create_table "dept_manager", force: :cascade do |t|
64
+ t.string "dept_no", limit: 4, null: false
65
+ t.date "from_date", null: false
66
+ t.date "to_date", null: false
67
+ end
68
+
69
+ create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
70
+ t.integer "emp_no", null: false
71
+ t.date "birth_date", null: false
72
+ t.string "first_name", limit: 14, null: false
73
+ t.string "last_name", limit: 16, null: false
74
+ t.string "gender", limit: 1, null: false
75
+ t.date "hire_date", null: false
76
+ end
77
+ EOS
78
+ }
79
+
80
+ let(:expected_dsl) {
81
+ erbh(<<-EOS)
82
+ create_table "dept_manager", force: :cascade do |t|
83
+ t.bigint "employee_id"
84
+ t.string "dept_no", limit: 4, null: false
85
+ t.date "from_date", null: false
86
+ t.date "to_date", null: false
87
+ end
88
+
89
+ create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
90
+ t.integer "emp_no", null: false
91
+ t.date "birth_date", null: false
92
+ t.string "first_name", limit: 14, null: false
93
+ t.string "last_name", limit: 16, null: false
94
+ t.string "gender", limit: 1, null: false
95
+ t.date "hire_date", null: false
96
+ end
97
+ EOS
98
+ }
99
+
100
+ before { subject.diff(actual_dsl).migrate }
101
+ subject { client(check_relation_type: 'bigint') }
102
+
103
+ it {
104
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
105
+ [WARNING] Relation column type is different.
106
+ employees.id: :type=>:bigint, :unsigned=>true
107
+ dept_manager.employee_id: :type=>:bigint
50
108
  EOS
51
109
 
52
110
  delta = subject.diff(expected_dsl)
@@ -109,4 +167,57 @@ describe 'Ridgepole::Client#diff -> migrate', 5.1 do
109
167
  expect(subject.dump).to match_fuzzy expected_dsl
110
168
  }
111
169
  end
170
+
171
+ context 'with unsigned warning' do
172
+ let(:actual_dsl) {
173
+ erbh(<<-EOS)
174
+ create_table "dept_manager", force: :cascade do |t|
175
+ t.string "dept_no", limit: 4, null: false
176
+ t.date "from_date", null: false
177
+ t.date "to_date", null: false
178
+ end
179
+
180
+ create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
181
+ t.integer "emp_no", null: false
182
+ t.date "birth_date", null: false
183
+ t.string "first_name", limit: 14, null: false
184
+ t.string "last_name", limit: 16, null: false
185
+ t.string "gender", limit: 1, null: false
186
+ t.date "hire_date", null: false
187
+ end
188
+ EOS
189
+ }
190
+
191
+ let(:expected_dsl) {
192
+ erbh(<<-EOS)
193
+ create_table "dept_manager", force: :cascade do |t|
194
+ t.bigint "employee_id", unsigned: true
195
+ t.string "dept_no", limit: 4, null: false
196
+ t.date "from_date", null: false
197
+ t.date "to_date", null: false
198
+ end
199
+
200
+ create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
201
+ t.integer "emp_no", null: false
202
+ t.date "birth_date", null: false
203
+ t.string "first_name", limit: 14, null: false
204
+ t.string "last_name", limit: 16, null: false
205
+ t.string "gender", limit: 1, null: false
206
+ t.date "hire_date", null: false
207
+ end
208
+ EOS
209
+ }
210
+
211
+ before { subject.diff(actual_dsl).migrate }
212
+ subject { client(check_relation_type: 'bigint') }
213
+
214
+ it {
215
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
216
+ delta = subject.diff(expected_dsl)
217
+ expect(delta.differ?).to be_truthy
218
+ expect(subject.dump).to match_fuzzy actual_dsl
219
+ delta.migrate
220
+ expect(subject.dump).to match_fuzzy expected_dsl
221
+ }
222
+ end
112
223
  end
@@ -0,0 +1,112 @@
1
+ describe 'Ridgepole::Client#diff -> migrate', condition: 5.1 do
2
+ context 'with warning' do
3
+ let(:actual_dsl) {
4
+ erbh(<<-EOS)
5
+ create_table "dept_manager", force: :cascade do |t|
6
+ t.string "dept_no", limit: 4, null: false
7
+ t.date "from_date", null: false
8
+ t.date "to_date", null: false
9
+ end
10
+
11
+ create_table "employees", id: :serial, force: :cascade do |t|
12
+ t.integer "emp_no", null: false
13
+ t.date "birth_date", null: false
14
+ t.string "first_name", limit: 14, null: false
15
+ t.string "last_name", limit: 16, null: false
16
+ t.string "gender", limit: 1, null: false
17
+ t.date "hire_date", null: false
18
+ end
19
+ EOS
20
+ }
21
+
22
+ let(:expected_dsl) {
23
+ erbh(<<-EOS)
24
+ create_table "dept_manager", force: :cascade do |t|
25
+ t.string "dept_no", limit: 4, null: false
26
+ t.date "from_date", null: false
27
+ t.date "to_date", null: false
28
+ t.bigint "employee_id"
29
+ end
30
+
31
+ create_table "employees", id: :serial, force: :cascade do |t|
32
+ t.integer "emp_no", null: false
33
+ t.date "birth_date", null: false
34
+ t.string "first_name", limit: 14, null: false
35
+ t.string "last_name", limit: 16, null: false
36
+ t.string "gender", limit: 1, null: false
37
+ t.date "hire_date", null: false
38
+ end
39
+ EOS
40
+ }
41
+
42
+ before { subject.diff(actual_dsl).migrate }
43
+ subject { client(check_relation_type: 'bigserial') }
44
+
45
+ it {
46
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
47
+ [WARNING] Relation column type is different.
48
+ employees.id: :type=>:integer
49
+ dept_manager.employee_id: :type=>:bigint
50
+ EOS
51
+
52
+ delta = subject.diff(expected_dsl)
53
+ expect(delta.differ?).to be_truthy
54
+ expect(subject.dump).to match_fuzzy actual_dsl
55
+ delta.migrate
56
+ expect(subject.dump).to match_fuzzy expected_dsl
57
+ }
58
+ end
59
+
60
+ context 'with warning' do
61
+ let(:actual_dsl) {
62
+ erbh(<<-EOS)
63
+ create_table "dept_manager", force: :cascade do |t|
64
+ t.string "dept_no", limit: 4, null: false
65
+ t.date "from_date", null: false
66
+ t.date "to_date", null: false
67
+ end
68
+
69
+ create_table "employees", id: :serial, force: :cascade do |t|
70
+ t.integer "emp_no", null: false
71
+ t.date "birth_date", null: false
72
+ t.string "first_name", limit: 14, null: false
73
+ t.string "last_name", limit: 16, null: false
74
+ t.string "gender", limit: 1, null: false
75
+ t.date "hire_date", null: false
76
+ end
77
+ EOS
78
+ }
79
+
80
+ let(:expected_dsl) {
81
+ erbh(<<-EOS)
82
+ create_table "dept_manager", force: :cascade do |t|
83
+ t.string "dept_no", limit: 4, null: false
84
+ t.date "from_date", null: false
85
+ t.date "to_date", null: false
86
+ t.integer "employee_id"
87
+ end
88
+
89
+ create_table "employees", id: :serial, force: :cascade do |t|
90
+ t.integer "emp_no", null: false
91
+ t.date "birth_date", null: false
92
+ t.string "first_name", limit: 14, null: false
93
+ t.string "last_name", limit: 16, null: false
94
+ t.string "gender", limit: 1, null: false
95
+ t.date "hire_date", null: false
96
+ end
97
+ EOS
98
+ }
99
+
100
+ before { subject.diff(actual_dsl).migrate }
101
+ subject { client(check_relation_type: 'bigserial') }
102
+
103
+ it {
104
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
105
+ delta = subject.diff(expected_dsl)
106
+ expect(delta.differ?).to be_truthy
107
+ expect(subject.dump).to match_fuzzy actual_dsl
108
+ delta.migrate
109
+ expect(subject.dump).to match_fuzzy expected_dsl
110
+ }
111
+ end
112
+ 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.7.0.beta8
4
+ version: 0.7.0.beta9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -339,6 +339,7 @@ files:
339
339
  - spec/postgresql/migrate/migrate_change_column_default_spec.rb
340
340
  - spec/postgresql/migrate/migrate_change_column_spec.rb
341
341
  - spec/postgresql/migrate/migrate_change_index_spec.rb
342
+ - spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb
342
343
  - spec/postgresql/migrate/migrate_create_table_spec.rb
343
344
  - spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb
344
345
  - spec/postgresql/migrate/migrate_drop_column_spec.rb
@@ -481,6 +482,7 @@ test_files:
481
482
  - spec/postgresql/migrate/migrate_change_column_default_spec.rb
482
483
  - spec/postgresql/migrate/migrate_change_column_spec.rb
483
484
  - spec/postgresql/migrate/migrate_change_index_spec.rb
485
+ - spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb
484
486
  - spec/postgresql/migrate/migrate_create_table_spec.rb
485
487
  - spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb
486
488
  - spec/postgresql/migrate/migrate_drop_column_spec.rb