ridgepole 0.7.3.beta2 → 0.7.3.beta3

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: acad17ac1fb19603bbf36ba03f17510ddd752db8
4
- data.tar.gz: 93ccceda898278fb96684aaaa23bff4a6b1a0fb2
3
+ metadata.gz: 7a40a3e0af48eec8639364ed4757e8af349cea63
4
+ data.tar.gz: 7cae592ecd1b5d9127988341ec8da8e072749a71
5
5
  SHA512:
6
- metadata.gz: 4013ac5fff9afef7c70282b2b1a26543ec08832e30e8551b18f8ae9f3e019629d6143a8167084bc0556d2d116a4a2822b449af34fcc64e0a00480cc01ceeaadf
7
- data.tar.gz: a081d8554675a28c9b55fefcb959d39d48c640ce768935b53eb0ccefdaff2a5e8b1eb84a3a1540ae4bde82c765af096dd17abb620412018f96b01c64247b3d46
6
+ metadata.gz: 5e9056bf844f8d96510f1d30537aadbf2a53de215045e92e96a1a3877c1cad2a5d597332e5f53aba2a983966a5956680845aea3da94bf6b138de97fdf0d11897
7
+ data.tar.gz: 45fc6de5dde52f208701d7bcc027a16fb7bc3c1f1b8fa463ce3bbbf4c4403b6a0fc34becb01ba80db897a853f8c3f306352cd8646634873e3932ae4e5cd8f631
data/README.md CHANGED
@@ -6,7 +6,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
6
6
  (like Chef/Puppet)
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/ridgepole.svg)](http://badge.fury.io/rb/ridgepole)
9
- [![Unstable Version](https://img.shields.io/badge/unstable-0.7.3.beta-green.svg?longCache=true&style=flat)](https://rubygems.org/gems/ridgepole/versions/0.7.3.beta)
9
+ [![Unstable Version](https://img.shields.io/badge/unstable-0.7.3.beta3-green.svg?longCache=true&style=flat)](https://rubygems.org/gems/ridgepole/versions/0.7.3.beta3)
10
10
  [![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.7)](https://travis-ci.org/winebarrel/ridgepole)
11
11
  [![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.7)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.7)
12
12
 
@@ -86,7 +86,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
86
86
  * `>= 0.7.3`
87
87
  * Add `--mysql-change-table-comment option` ([pull#166](https://github.com/winebarrel/ridgepole/pull/166))
88
88
  * Refactoring with RuboCop
89
- * Support primary key dropping ([issue#246](https://github.com/winebarrel/ridgepole/issues/246))
89
+ * Support primary key adding/dropping ([issue#246](https://github.com/winebarrel/ridgepole/issues/246))
90
90
 
91
91
  ## Installation
92
92
 
@@ -139,7 +139,13 @@ module Ridgepole
139
139
  pk_attrs = build_primary_key_attrs_if_changed(from, to, table_name)
140
140
  if pk_attrs
141
141
  if @options[:allow_pk_change]
142
- delta_type = pk_attrs[:options][:id] == false ? :delete : :change
142
+ if from[:id] == false
143
+ delta_type = :add
144
+ pk_attrs[:options][:primary_key] = true
145
+ else
146
+ delta_type = pk_attrs[:options][:id] == false ? :delete : :change
147
+ end
148
+
143
149
  table_delta[:primary_key_definition] = { delta_type => { id: pk_attrs } }
144
150
  else
145
151
  @logger.warn(<<-MSG)
@@ -170,7 +176,7 @@ module Ridgepole
170
176
  Ridgepole::DSLParser::TableDefinition::DEFAULT_PRIMARY_KEY_TYPE
171
177
  end
172
178
 
173
- if %i[integer bigint].include?(type) && !options.key?(:default)
179
+ if %i[integer bigint].include?(type) && !options.key?(:default) && !Ridgepole::ConnectionAdapters.postgresql?
174
180
  options[:auto_increment] = true
175
181
  end
176
182
 
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.7.3.beta2'.freeze
2
+ VERSION = '0.7.3.beta3'.freeze
3
3
  end
@@ -0,0 +1,71 @@
1
+ describe 'Ridgepole::Client#diff -> migrate', condition: '>= 5.1.0' do
2
+ let(:actual_dsl) do
3
+ erbh(<<-ERB)
4
+ create_table "employees", id: false, force: :cascade do |t|
5
+ t.string "name"
6
+ end
7
+ ERB
8
+ end
9
+
10
+ before do
11
+ subject.diff('').migrate
12
+ subject.diff(actual_dsl).migrate
13
+ end
14
+ subject { client(allow_pk_change: allow_pk_change) }
15
+
16
+ context 'when allow_pk_change option is false' do
17
+ let(:allow_pk_change) { false }
18
+
19
+ context 'with difference' do
20
+ let(:expected_dsl) do
21
+ erbh(<<-ERB)
22
+ create_table "employees", id: :bigint, force: :cascade do |t|
23
+ t.string "name"
24
+ end
25
+ ERB
26
+ end
27
+
28
+ it {
29
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-MSG)
30
+ [WARNING] Primary key definition of `employees` differ but `allow_pk_change` option is false
31
+ from: {:id=>false}
32
+ to: {:id=>:bigint}
33
+ MSG
34
+
35
+ delta = subject.diff(expected_dsl)
36
+ expect(delta.differ?).to be_falsey
37
+ delta.migrate
38
+ expect(subject.dump).to match_ruby actual_dsl
39
+ }
40
+ end
41
+
42
+ context 'with no difference' do
43
+ let(:expected_dsl) { actual_dsl }
44
+
45
+ it {
46
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
47
+
48
+ delta = subject.diff(expected_dsl)
49
+ expect(delta.differ?).to be_falsey
50
+ }
51
+ end
52
+ end
53
+
54
+ context 'when allow_pk_change option is true' do
55
+ let(:allow_pk_change) { true }
56
+ let(:expected_dsl) do
57
+ erbh(<<-ERB)
58
+ create_table "employees", id: :serial, force: :cascade do |t|
59
+ t.string "name"
60
+ end
61
+ ERB
62
+ end
63
+
64
+ it {
65
+ delta = subject.diff(expected_dsl)
66
+ expect(delta.differ?).to be_truthy
67
+ delta.migrate
68
+ expect(subject.dump).to match_ruby expected_dsl
69
+ }
70
+ end
71
+ 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.3.beta2
4
+ version: 0.7.3.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -390,6 +390,7 @@ files:
390
390
  - spec/postgresql/migrate/migrate_drop_index_spec.rb
391
391
  - spec/postgresql/migrate/migrate_drop_table_spec.rb
392
392
  - spec/postgresql/migrate/migrate_ext_cols_spec.rb
393
+ - spec/postgresql/migrate/migrate_primary_key2_spec.rb
393
394
  - spec/postgresql/migrate/migrate_primary_key_spec.rb
394
395
  - spec/postgresql/migrate/migrate_references_spec.rb
395
396
  - spec/postgresql/migrate/migrate_rename_column_spec.rb
@@ -546,6 +547,7 @@ test_files:
546
547
  - spec/postgresql/migrate/migrate_drop_index_spec.rb
547
548
  - spec/postgresql/migrate/migrate_drop_table_spec.rb
548
549
  - spec/postgresql/migrate/migrate_ext_cols_spec.rb
550
+ - spec/postgresql/migrate/migrate_primary_key2_spec.rb
549
551
  - spec/postgresql/migrate/migrate_primary_key_spec.rb
550
552
  - spec/postgresql/migrate/migrate_references_spec.rb
551
553
  - spec/postgresql/migrate/migrate_rename_column_spec.rb