ridgepole 0.6.5.beta7 → 0.6.5.beta8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/ridgepole.rb +3 -0
- data/lib/ridgepole/diff.rb +17 -0
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +1 -0
- data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +64 -0
- data/spec/postgresql/migrate/migrate_bigint_spec.rb +67 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8adb357a8559da5ebe42cc89f6e8916c2c387c39
|
4
|
+
data.tar.gz: f03ec0b86a0289241ebb64c42fa9eb0d3bdbdd6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab0dd2cc1ad788f6728407421f9b77ea81f641f8d8ea7d665a6fef4e6123c2dbb59db72bcdb01192d12c338622db356f0b82edeaf24df0be3a6b922606e65b3b
|
7
|
+
data.tar.gz: 8fa5ba2e3478b9e83c3da2bb332452e717b57da509b54385de35c2ef6c6a4efe41d7de25b86155c15ed74ead0cc0be958f52bed291a635f8ce2c4c47c4a8fbaf
|
data/README.md
CHANGED
@@ -55,6 +55,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
55
55
|
* Support new types ([pull#84](https://github.com/winebarrel/ridgepole/pull/84))
|
56
56
|
* Support `default: -> { ... }` ([pull#85](https://github.com/winebarrel/ridgepole/pull/85))
|
57
57
|
* Support DDL Comment (Rails5 only)
|
58
|
+
* Output schema diff when `--version`
|
58
59
|
|
59
60
|
## Installation
|
60
61
|
|
data/lib/ridgepole.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'open3'
|
3
|
+
require 'pp'
|
3
4
|
require 'shellwords'
|
4
5
|
require 'singleton'
|
5
6
|
require 'stringio'
|
@@ -8,6 +9,8 @@ require 'active_record'
|
|
8
9
|
require 'active_support'
|
9
10
|
require 'active_support/core_ext'
|
10
11
|
|
12
|
+
require 'diffy'
|
13
|
+
|
11
14
|
module Ridgepole; end
|
12
15
|
|
13
16
|
require 'ridgepole/client'
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Ridgepole::Diff
|
2
2
|
def initialize(options = {})
|
3
3
|
@options = options
|
4
|
+
@logger = Ridgepole::Logger.instance
|
4
5
|
end
|
5
6
|
|
6
7
|
def diff(from, to, options = {})
|
@@ -20,6 +21,12 @@ class Ridgepole::Diff
|
|
20
21
|
next unless target?(table_name)
|
21
22
|
|
22
23
|
if (from_attrs = from.delete(table_name))
|
24
|
+
@logger.verbose_info("# #{table_name}")
|
25
|
+
|
26
|
+
unless (attrs_delta = diff_inspect(from_attrs, to_attrs)).empty?
|
27
|
+
@logger.verbose_info(attrs_delta)
|
28
|
+
end
|
29
|
+
|
23
30
|
scan_change(table_name, from_attrs, to_attrs, delta)
|
24
31
|
else
|
25
32
|
delta[:add] ||= {}
|
@@ -358,4 +365,14 @@ class Ridgepole::Diff
|
|
358
365
|
|
359
366
|
attrs1 == attrs2
|
360
367
|
end
|
368
|
+
|
369
|
+
def diff_inspect(obj1, obj2, options = {})
|
370
|
+
diffy = Diffy::Diff.new(
|
371
|
+
obj1.pretty_inspect,
|
372
|
+
obj2.pretty_inspect,
|
373
|
+
:diff => '-u'
|
374
|
+
)
|
375
|
+
|
376
|
+
diffy.to_s(:text).gsub(/\s+\z/m, '')
|
377
|
+
end
|
361
378
|
end
|
data/lib/ridgepole/version.rb
CHANGED
data/ridgepole.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'activerecord', '>= 4.2', '< 6'
|
22
|
+
spec.add_dependency 'diffy'
|
22
23
|
spec.add_development_dependency 'bundler'
|
23
24
|
spec.add_development_dependency 'rake'
|
24
25
|
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'with verbose log' do
|
3
|
+
let(:actual_dsl) {
|
4
|
+
erbh(<<-EOS)
|
5
|
+
create_table "employees", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %> 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
|
+
end
|
12
|
+
EOS
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:expected_dsl) {
|
16
|
+
erbh(<<-EOS)
|
17
|
+
create_table "employees", primary_key: "emp_no", <%= i unsigned(true) + {force: :cascade} %> do |t|
|
18
|
+
t.date "birth_date", null: false
|
19
|
+
t.string "first_name", limit: 14, null: false
|
20
|
+
t.string "last_name", limit: 16, null: false
|
21
|
+
t.string "gender2", limit: 1, null: false
|
22
|
+
t.date "hire_date", null: false
|
23
|
+
end
|
24
|
+
EOS
|
25
|
+
}
|
26
|
+
|
27
|
+
before { subject.diff(actual_dsl).migrate }
|
28
|
+
subject { client }
|
29
|
+
|
30
|
+
it {
|
31
|
+
verbose_infos = []
|
32
|
+
allow(Ridgepole::Logger.instance).to receive(:verbose_info) {|m| verbose_infos << m }
|
33
|
+
|
34
|
+
Ridgepole::Logger.verbose = true
|
35
|
+
delta = subject.diff(expected_dsl)
|
36
|
+
expect(delta.differ?).to be_truthy
|
37
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
38
|
+
delta.migrate
|
39
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
40
|
+
Ridgepole::Logger.verbose = false
|
41
|
+
|
42
|
+
expected_verbose_infos = [
|
43
|
+
"# Parse DSL",
|
44
|
+
"# Load tables",
|
45
|
+
"# employees",
|
46
|
+
"# Compare definitions",
|
47
|
+
"# employees",
|
48
|
+
"# Load tables",
|
49
|
+
"# employees",
|
50
|
+
"# Load tables",
|
51
|
+
"# employees",
|
52
|
+
]
|
53
|
+
|
54
|
+
|
55
|
+
if condition(:mysql_awesome_enabled)
|
56
|
+
expected_verbose_infos << " {\"birth_date\"=>{:type=>:date, :options=>{:null=>false}},\n \"first_name\"=>{:type=>:string, :options=>{:limit=>14, :null=>false}},\n \"last_name\"=>{:type=>:string, :options=>{:limit=>16, :null=>false}},\n- \"gender\"=>{:type=>:string, :options=>{:limit=>1, :null=>false}},\n+ \"gender2\"=>{:type=>:string, :options=>{:limit=>1, :null=>false}},\n \"hire_date\"=>{:type=>:date, :options=>{:null=>false}}},\n :options=>{:primary_key=>\"emp_no\", :unsigned=>true}}"
|
57
|
+
else
|
58
|
+
expected_verbose_infos << " {\"birth_date\"=>{:type=>:date, :options=>{:null=>false}},\n \"first_name\"=>{:type=>:string, :options=>{:limit=>14, :null=>false}},\n \"last_name\"=>{:type=>:string, :options=>{:limit=>16, :null=>false}},\n- \"gender\"=>{:type=>:string, :options=>{:limit=>1, :null=>false}},\n+ \"gender2\"=>{:type=>:string, :options=>{:limit=>1, :null=>false}},\n \"hire_date\"=>{:type=>:date, :options=>{:null=>false}}},\n :options=>{:primary_key=>\"emp_no\"}}"
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(verbose_infos).to match_array expected_verbose_infos
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when add bigint column' do
|
3
|
+
let(:actual_dsl) { '' }
|
4
|
+
|
5
|
+
let(:expected_dsl) {
|
6
|
+
if condition(:activerecord_5)
|
7
|
+
erbh(<<-EOS)
|
8
|
+
create_table "bigint_test", id: false, force: :cascade do |t|
|
9
|
+
t.bigint "b"
|
10
|
+
end
|
11
|
+
EOS
|
12
|
+
else
|
13
|
+
erbh(<<-EOS)
|
14
|
+
create_table "bigint_test", id: false, force: :cascade do |t|
|
15
|
+
t.integer "b", limit: 8
|
16
|
+
end
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
}
|
20
|
+
|
21
|
+
before { subject.diff(actual_dsl).migrate }
|
22
|
+
subject { client }
|
23
|
+
|
24
|
+
it {
|
25
|
+
delta = subject.diff(expected_dsl)
|
26
|
+
expect(delta.differ?).to be_truthy
|
27
|
+
delta.migrate
|
28
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when no change' do
|
33
|
+
let(:dsl) {
|
34
|
+
erbh(<<-EOS)
|
35
|
+
create_table "bigint_test", id: false, force: :cascade do |t|
|
36
|
+
t.bigint "b"
|
37
|
+
end
|
38
|
+
EOS
|
39
|
+
}
|
40
|
+
|
41
|
+
let(:expected_dsl) {
|
42
|
+
if condition(:activerecord_5)
|
43
|
+
erbh(<<-EOS)
|
44
|
+
create_table "bigint_test", id: false, force: :cascade do |t|
|
45
|
+
t.bigint "b"
|
46
|
+
end
|
47
|
+
EOS
|
48
|
+
else
|
49
|
+
erbh(<<-EOS)
|
50
|
+
create_table "bigint_test", id: false, force: :cascade do |t|
|
51
|
+
t.integer "b", limit: 8
|
52
|
+
end
|
53
|
+
EOS
|
54
|
+
end
|
55
|
+
}
|
56
|
+
|
57
|
+
before { subject.diff(dsl).migrate }
|
58
|
+
subject { client }
|
59
|
+
|
60
|
+
it {
|
61
|
+
delta = subject.diff(expected_dsl)
|
62
|
+
expect(delta.differ?).to be_falsey
|
63
|
+
delta.migrate
|
64
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
65
|
+
}
|
66
|
+
end
|
67
|
+
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.beta8
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '6'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: diffy
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: bundler
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -289,6 +303,7 @@ files:
|
|
289
303
|
- spec/mysql/migrate/migrate_with_ignore_tables_spec.rb
|
290
304
|
- spec/mysql/migrate/migrate_with_pre_post_query_spec.rb
|
291
305
|
- spec/mysql/migrate/migrate_with_tables_spec.rb
|
306
|
+
- spec/mysql/migrate/migrate_with_verbose_log_spec.rb
|
292
307
|
- spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb
|
293
308
|
- spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb
|
294
309
|
- spec/mysql/ridgepole_test_database.sql
|
@@ -303,6 +318,7 @@ files:
|
|
303
318
|
- spec/postgresql/fk/migrate_create_fk_spec.rb
|
304
319
|
- spec/postgresql/fk/migrate_drop_fk_spec.rb
|
305
320
|
- spec/postgresql/migrate/migrate_add_column_spec.rb
|
321
|
+
- spec/postgresql/migrate/migrate_bigint_spec.rb
|
306
322
|
- spec/postgresql/migrate/migrate_change_column_default_spec.rb
|
307
323
|
- spec/postgresql/migrate/migrate_change_column_spec.rb
|
308
324
|
- spec/postgresql/migrate/migrate_change_index_spec.rb
|
@@ -415,6 +431,7 @@ test_files:
|
|
415
431
|
- spec/mysql/migrate/migrate_with_ignore_tables_spec.rb
|
416
432
|
- spec/mysql/migrate/migrate_with_pre_post_query_spec.rb
|
417
433
|
- spec/mysql/migrate/migrate_with_tables_spec.rb
|
434
|
+
- spec/mysql/migrate/migrate_with_verbose_log_spec.rb
|
418
435
|
- spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb
|
419
436
|
- spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb
|
420
437
|
- spec/mysql/ridgepole_test_database.sql
|
@@ -429,6 +446,7 @@ test_files:
|
|
429
446
|
- spec/postgresql/fk/migrate_create_fk_spec.rb
|
430
447
|
- spec/postgresql/fk/migrate_drop_fk_spec.rb
|
431
448
|
- spec/postgresql/migrate/migrate_add_column_spec.rb
|
449
|
+
- spec/postgresql/migrate/migrate_bigint_spec.rb
|
432
450
|
- spec/postgresql/migrate/migrate_change_column_default_spec.rb
|
433
451
|
- spec/postgresql/migrate/migrate_change_column_spec.rb
|
434
452
|
- spec/postgresql/migrate/migrate_change_index_spec.rb
|