ridgepole 0.6.5.beta8 → 0.6.5.beta9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/docker-compose.yml +1 -1
- data/lib/ridgepole/delta.rb +7 -7
- data/lib/ridgepole/diff.rb +12 -5
- data/lib/ridgepole/version.rb +1 -1
- data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +92 -0
- data/spec/postgresql/ridgepole_test_database.sql +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 024470270cd96b582a5e6c0da47e8ca57bfae9a6
|
4
|
+
data.tar.gz: 870ce03f5efdf6d1cf888b35a22367524189fb39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abfb2f146e7b6d57a72fdf4735227cc9e82e4cb11a1859dfc9666bc7c5c5851539c7a2891edc47075b02c6a09099d911f50f320d26de71e3a845b10a21733cc5
|
7
|
+
data.tar.gz: bca1b088bd0c3943202d51b49ea35304ca7adef09cd5d52581df67527340dfcb86f8262339f1a239ac7d3ee70fadc9c6722c8945c9698d81c2666134ccec6c0c
|
data/.gitignore
CHANGED
data/docker-compose.yml
CHANGED
data/lib/ridgepole/delta.rb
CHANGED
@@ -218,7 +218,7 @@ class Ridgepole::Delta
|
|
218
218
|
indices = attrs[:indices] || {}
|
219
219
|
|
220
220
|
buf.puts(<<-EOS)
|
221
|
-
create_table(#{table_name.inspect}, #{options
|
221
|
+
create_table(#{table_name.inspect}, #{inspect_options_include_default_proc(options)}) do |t|
|
222
222
|
EOS
|
223
223
|
|
224
224
|
definition.each do |column_name, column_attrs|
|
@@ -227,7 +227,7 @@ create_table(#{table_name.inspect}, #{options.inspect}) do |t|
|
|
227
227
|
normalize_limit(column_type, column_options)
|
228
228
|
|
229
229
|
buf.puts(<<-EOS)
|
230
|
-
t.#{column_type}(#{column_name.inspect}, #{
|
230
|
+
t.#{column_type}(#{column_name.inspect}, #{inspect_options_include_default_proc(column_options)})
|
231
231
|
EOS
|
232
232
|
end
|
233
233
|
|
@@ -320,11 +320,11 @@ drop_table(#{table_name.inspect})
|
|
320
320
|
|
321
321
|
if @options[:bulk_change]
|
322
322
|
buf.puts(<<-EOS)
|
323
|
-
t.column(#{column_name.inspect}, #{type.inspect}, #{
|
323
|
+
t.column(#{column_name.inspect}, #{type.inspect}, #{inspect_options_include_default_proc(options)})
|
324
324
|
EOS
|
325
325
|
else
|
326
326
|
buf.puts(<<-EOS)
|
327
|
-
add_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{
|
327
|
+
add_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{inspect_options_include_default_proc(options)})
|
328
328
|
EOS
|
329
329
|
end
|
330
330
|
end
|
@@ -347,11 +347,11 @@ rename_column(#{table_name.inspect}, #{from_column_name.inspect}, #{to_column_na
|
|
347
347
|
|
348
348
|
if @options[:bulk_change]
|
349
349
|
buf.puts(<<-EOS)
|
350
|
-
t.change(#{column_name.inspect}, #{type.inspect}, #{
|
350
|
+
t.change(#{column_name.inspect}, #{type.inspect}, #{inspect_options_include_default_proc(options)})
|
351
351
|
EOS
|
352
352
|
else
|
353
353
|
buf.puts(<<-EOS)
|
354
|
-
change_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{
|
354
|
+
change_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{inspect_options_include_default_proc(options)})
|
355
355
|
EOS
|
356
356
|
end
|
357
357
|
end
|
@@ -446,7 +446,7 @@ remove_foreign_key(#{table_name.inspect}, #{target.inspect})
|
|
446
446
|
column_options[:limit] ||= default_limit if default_limit
|
447
447
|
end
|
448
448
|
|
449
|
-
def
|
449
|
+
def inspect_options_include_default_proc(options)
|
450
450
|
options = options.dup
|
451
451
|
|
452
452
|
if options[:default].kind_of?(Proc)
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -94,6 +94,11 @@ class Ridgepole::Diff
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def scan_options_change(table_name, from, to, table_delta)
|
97
|
+
from = (from || {}).dup
|
98
|
+
to = (to || {}).dup
|
99
|
+
|
100
|
+
normalize_default_proc_options!(from, to)
|
101
|
+
|
97
102
|
unless from == to
|
98
103
|
Ridgepole::Logger.instance.warn("[WARNING] No difference of schema configuration for table `#{table_name}` but table options differ.")
|
99
104
|
Ridgepole::Logger.instance.warn(" from: #{from}")
|
@@ -357,13 +362,15 @@ class Ridgepole::Diff
|
|
357
362
|
def compare_column_attrs(attrs1, attrs2)
|
358
363
|
attrs1 = attrs1.merge(:options => attrs1.fetch(:options, {}).dup)
|
359
364
|
attrs2 = attrs2.merge(:options => attrs2.fetch(:options, {}).dup)
|
365
|
+
normalize_default_proc_options!(attrs1[:options], attrs2[:options])
|
366
|
+
attrs1 == attrs2
|
367
|
+
end
|
360
368
|
|
361
|
-
|
362
|
-
|
363
|
-
|
369
|
+
def normalize_default_proc_options!(opts1, opts2)
|
370
|
+
if opts1[:default].kind_of?(Proc) and opts2[:default].kind_of?(Proc)
|
371
|
+
opts1[:default] = opts1[:default].call
|
372
|
+
opts2[:default] = opts2[:default].call
|
364
373
|
end
|
365
|
-
|
366
|
-
attrs1 == attrs2
|
367
374
|
end
|
368
375
|
|
369
376
|
def diff_inspect(obj1, obj2, options = {})
|
data/lib/ridgepole/version.rb
CHANGED
@@ -0,0 +1,92 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate', condition: [:activerecord_5] do
|
2
|
+
context 'when create table with default proc' do
|
3
|
+
let(:dsl) { '' }
|
4
|
+
|
5
|
+
let(:actual_dsl) {
|
6
|
+
erbh(<<-EOS)
|
7
|
+
create_table "users", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t|
|
8
|
+
t.string "name"
|
9
|
+
t.datetime "created_at", null: false
|
10
|
+
t.datetime "updated_at", null: false
|
11
|
+
end
|
12
|
+
EOS
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:expected_dsl) { dsl }
|
16
|
+
|
17
|
+
before { subject.diff(actual_dsl).migrate }
|
18
|
+
subject { client }
|
19
|
+
|
20
|
+
it {
|
21
|
+
expect(Ridgepole::Logger.instance).to_not receive(:warn)
|
22
|
+
|
23
|
+
delta = subject.diff(expected_dsl)
|
24
|
+
expect(delta.differ?).to be_truthy
|
25
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
26
|
+
delta.migrate
|
27
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when create table with default proc without change' do
|
32
|
+
let(:dsl) {
|
33
|
+
erbh(<<-EOS)
|
34
|
+
create_table "users", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t|
|
35
|
+
t.string "name"
|
36
|
+
t.datetime "created_at", null: false
|
37
|
+
t.datetime "updated_at", null: false
|
38
|
+
end
|
39
|
+
EOS
|
40
|
+
}
|
41
|
+
|
42
|
+
before { subject.diff(dsl).migrate }
|
43
|
+
subject { client }
|
44
|
+
|
45
|
+
it {
|
46
|
+
expect(Ridgepole::Logger.instance).to_not receive(:warn)
|
47
|
+
|
48
|
+
delta = subject.diff(dsl)
|
49
|
+
expect(delta.differ?).to be_falsey
|
50
|
+
expect(subject.dump).to match_fuzzy dsl
|
51
|
+
delta.migrate
|
52
|
+
expect(subject.dump).to match_fuzzy dsl
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when migrate table with default proc' do
|
57
|
+
let(:actual_dsl) {
|
58
|
+
erbh(<<-EOS)
|
59
|
+
create_table "users", id: :uuid, default: -> { "uuid_generate_v1()" }, force: :cascade do |t|
|
60
|
+
t.string "name"
|
61
|
+
t.datetime "created_at", null: false
|
62
|
+
t.datetime "updated_at", null: false
|
63
|
+
end
|
64
|
+
EOS
|
65
|
+
}
|
66
|
+
|
67
|
+
let(:expected_dsl) {
|
68
|
+
erbh(<<-EOS)
|
69
|
+
create_table "users", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t|
|
70
|
+
t.string "name"
|
71
|
+
t.datetime "created_at", null: false
|
72
|
+
t.datetime "updated_at", null: false
|
73
|
+
end
|
74
|
+
EOS
|
75
|
+
}
|
76
|
+
|
77
|
+
before { subject.diff(actual_dsl).migrate }
|
78
|
+
subject { client }
|
79
|
+
|
80
|
+
it {
|
81
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with("[WARNING] No difference of schema configuration for table `users` but table options differ.")
|
82
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! from: {:id=>:uuid, :default=>"uuid_generate_v1()"}!))
|
83
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! to: {:id=>:uuid, :default=>"uuid_generate_v4()"}!))
|
84
|
+
|
85
|
+
delta = subject.diff(expected_dsl)
|
86
|
+
expect(delta.differ?).to be_falsey
|
87
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
88
|
+
delta.migrate
|
89
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
90
|
+
}
|
91
|
+
end
|
92
|
+
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.5.
|
4
|
+
version: 0.6.5.beta9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -323,6 +323,7 @@ files:
|
|
323
323
|
- spec/postgresql/migrate/migrate_change_column_spec.rb
|
324
324
|
- spec/postgresql/migrate/migrate_change_index_spec.rb
|
325
325
|
- spec/postgresql/migrate/migrate_create_table_spec.rb
|
326
|
+
- spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb
|
326
327
|
- spec/postgresql/migrate/migrate_drop_column_spec.rb
|
327
328
|
- spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb
|
328
329
|
- spec/postgresql/migrate/migrate_drop_index_spec.rb
|
@@ -451,6 +452,7 @@ test_files:
|
|
451
452
|
- spec/postgresql/migrate/migrate_change_column_spec.rb
|
452
453
|
- spec/postgresql/migrate/migrate_change_index_spec.rb
|
453
454
|
- spec/postgresql/migrate/migrate_create_table_spec.rb
|
455
|
+
- spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb
|
454
456
|
- spec/postgresql/migrate/migrate_drop_column_spec.rb
|
455
457
|
- spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb
|
456
458
|
- spec/postgresql/migrate/migrate_drop_index_spec.rb
|