ridgepole 0.7.0.beta7 → 0.7.0.beta8
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 +4 -4
- data/README.md +28 -1
- data/bin/ridgepole +17 -16
- data/lib/ridgepole/diff.rb +65 -0
- data/lib/ridgepole/version.rb +1 -1
- data/spec/mysql/cli/ridgepole_spec.rb +1 -0
- data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +112 -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: 6379a32db8dc48969ccf8c184534eccdea98fdd0
|
4
|
+
data.tar.gz: efbb7beeb7656df70ed62a102585f7ef2bbe17d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dfbe2a44db029662943ad2f447e4d72a26f9d970807336f0cce0806cf1758337e1f65587cd9ba0b7496887e87ebcd82d0a42cec842fd2443e90bb5b8c4cf63b
|
7
|
+
data.tar.gz: 4ba605415d1d48c00eb462f9dc6573c1ee131c456eb9cc215f471604b401f11972a4023ee6c14664a2c23a21a274c6b466c9e78564092cc63e034225f2ba54bb
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
9
9
|
[](https://travis-ci.org/winebarrel/ridgepole)
|
10
10
|
[](https://coveralls.io/github/winebarrel/ridgepole?branch=0.6)
|
11
11
|
|
12
|
-
[](https://rubygems.org/gems/ridgepole/versions/0.7.0.beta8)
|
13
13
|
[](https://travis-ci.org/winebarrel/ridgepole)
|
14
14
|
[](https://coveralls.io/github/winebarrel/ridgepole?branch=0.7)
|
15
15
|
|
@@ -75,6 +75,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
75
75
|
* Add `--mysql-change-table-options` option
|
76
76
|
* Pass config from env
|
77
77
|
* Fix change fk order
|
78
|
+
* Add `--check-relation-type` option
|
78
79
|
|
79
80
|
## Installation
|
80
81
|
|
@@ -126,6 +127,7 @@ Usage: ridgepole [options]
|
|
126
127
|
--index-removed-drop-column
|
127
128
|
--skip-drop-table
|
128
129
|
--mysql-change-table-options
|
130
|
+
--check-relation-type DEF_PK
|
129
131
|
-r, --require LIBS
|
130
132
|
--log-file LOG_FILE
|
131
133
|
--verbose
|
@@ -350,6 +352,31 @@ Apply `Schemafile`
|
|
350
352
|
-> 0.0243s
|
351
353
|
```
|
352
354
|
|
355
|
+
## Relation column type check
|
356
|
+
|
357
|
+
```ruby
|
358
|
+
create_table "employees", force: :cascade do |t|
|
359
|
+
t.integer "emp_no", null: false
|
360
|
+
t.string "first_name", limit: 14, null: false
|
361
|
+
t.string "last_name", limit: 16, null: false
|
362
|
+
end
|
363
|
+
|
364
|
+
create_table "dept_manager", force: :cascade do |t|
|
365
|
+
t.integer "employee_id"
|
366
|
+
t.string "dept_no", limit: 4, null: false
|
367
|
+
end
|
368
|
+
```
|
369
|
+
|
370
|
+
```sh
|
371
|
+
$ ridgepole -a -c database.yml --check-relation-type bigint # default primary key type (e.g. `<5.1`: integer, `>=5.1`: bigint for MySQL)
|
372
|
+
Apply `Schemafile`
|
373
|
+
...
|
374
|
+
[WARNING] Relation column type is different.
|
375
|
+
employees.id: bigint
|
376
|
+
dept_manager.employee_id: integer
|
377
|
+
...
|
378
|
+
```
|
379
|
+
|
353
380
|
## Running tests
|
354
381
|
|
355
382
|
```sh
|
data/bin/ridgepole
CHANGED
@@ -110,22 +110,23 @@ ARGV.options do |opt|
|
|
110
110
|
ARGV.shift
|
111
111
|
diff_files = [diff_arg1, diff_arg2]
|
112
112
|
}
|
113
|
-
opt.on('', '--reverse')
|
114
|
-
opt.on('', '--with-apply')
|
115
|
-
opt.on('-o', '--output SCHEMAFILE')
|
116
|
-
opt.on('-t', '--tables TABLES', Array)
|
117
|
-
opt.on('', '--ignore-tables REGEX_LIST', Array)
|
118
|
-
opt.on('', '--mysql-use-alter')
|
119
|
-
opt.on('', '--dump-without-table-options')
|
120
|
-
opt.on('', '--dump-with-default-fk-name')
|
121
|
-
opt.on('', '--index-removed-drop-column')
|
122
|
-
opt.on('', '--skip-drop-table')
|
123
|
-
opt.on('', '--mysql-change-table-options')
|
124
|
-
opt.on('
|
125
|
-
opt.on(''
|
126
|
-
opt.on('' , '--
|
127
|
-
opt.on('' , '--
|
128
|
-
opt.on('' , '--
|
113
|
+
opt.on('', '--reverse') { options[:reverse] = true }
|
114
|
+
opt.on('', '--with-apply') { diff_with_apply = true }
|
115
|
+
opt.on('-o', '--output SCHEMAFILE') {|v| output_file = v }
|
116
|
+
opt.on('-t', '--tables TABLES', Array) {|v| options[:tables] = v }
|
117
|
+
opt.on('', '--ignore-tables REGEX_LIST', Array) {|v| options[:ignore_tables] = v.map {|i| Regexp.new(i) } }
|
118
|
+
opt.on('', '--mysql-use-alter') { options[:mysql_use_alter] = true }
|
119
|
+
opt.on('', '--dump-without-table-options') { options[:dump_without_table_options] = true }
|
120
|
+
opt.on('', '--dump-with-default-fk-name') { options[:dump_with_default_fk_name] = true }
|
121
|
+
opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
|
122
|
+
opt.on('', '--skip-drop-table') { options[:skip_drop_table] = true }
|
123
|
+
opt.on('', '--mysql-change-table-options') { options[:mysql_change_table_options] = true }
|
124
|
+
opt.on('', '--check-relation-type DEF_PK') {|v| options[:check_relation_type] = v }
|
125
|
+
opt.on('-r', '--require LIBS', Array) {|v| v.each {|i| require i } }
|
126
|
+
opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v }
|
127
|
+
opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true }
|
128
|
+
opt.on('' , '--debug') { options[:debug] = true }
|
129
|
+
opt.on('' , '--[no-]color') {|v| options[:color] = v }
|
129
130
|
|
130
131
|
opt.on('-v', '--version') {
|
131
132
|
puts opt.ver
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -13,11 +13,15 @@ class Ridgepole::Diff
|
|
13
13
|
end
|
14
14
|
|
15
15
|
delta = {}
|
16
|
+
relation_info = {}
|
17
|
+
|
16
18
|
scan_table_rename(from, to, delta)
|
17
19
|
# for reverse option
|
18
20
|
scan_table_rename(to, from, delta)
|
19
21
|
|
20
22
|
to.each do |table_name, to_attrs|
|
23
|
+
collect_relation_info!(table_name, to_attrs, relation_info)
|
24
|
+
|
21
25
|
next unless target?(table_name)
|
22
26
|
|
23
27
|
if (from_attrs = from.delete(table_name))
|
@@ -34,6 +38,8 @@ class Ridgepole::Diff
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
41
|
+
scan_relation_info(relation_info)
|
42
|
+
|
37
43
|
unless @options[:merge] or @options[:skip_drop_table]
|
38
44
|
from.each do |table_name, from_attrs|
|
39
45
|
next unless target?(table_name)
|
@@ -419,4 +425,63 @@ class Ridgepole::Diff
|
|
419
425
|
diffy.to_s(@options[:color] ? :color : :text).gsub(/\s+\z/m, '')
|
420
426
|
end
|
421
427
|
|
428
|
+
def collect_relation_info!(table_name, table_attr, relation_info)
|
429
|
+
return unless @options[:check_relation_type]
|
430
|
+
|
431
|
+
attrs_by_column = {}
|
432
|
+
definition = table_attr[:definition] || {}
|
433
|
+
|
434
|
+
definition.each do |column_name, column_attrs|
|
435
|
+
if column_name =~ /\w+_id\z/
|
436
|
+
attrs_by_column[column_name] = column_attrs.dup
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
relation_info[table_name] = {
|
441
|
+
:options => table_attr[:options] || {},
|
442
|
+
:columns => attrs_by_column,
|
443
|
+
}
|
444
|
+
end
|
445
|
+
|
446
|
+
def scan_relation_info(relation_info)
|
447
|
+
return unless @options[:check_relation_type]
|
448
|
+
|
449
|
+
relation_info.each do |child_table, table_info|
|
450
|
+
next unless target?(child_table)
|
451
|
+
|
452
|
+
attrs_by_column = table_info.fetch(:columns)
|
453
|
+
parent_table_info = nil
|
454
|
+
|
455
|
+
attrs_by_column.each do |column_name, column_attrs|
|
456
|
+
parent_table = column_name.sub(/_id\z/, '')
|
457
|
+
|
458
|
+
[parent_table.pluralize, parent_table.singularize].each do |table_name|
|
459
|
+
parent_table_info = relation_info[table_name]
|
460
|
+
|
461
|
+
if parent_table_info
|
462
|
+
parent_table = table_name
|
463
|
+
break
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
next unless parent_table_info
|
468
|
+
|
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
|
+
|
473
|
+
if pk_type != child_column_type
|
474
|
+
parent_label = "#{parent_table}.id"
|
475
|
+
child_label = "#{child_table}.#{column_name}"
|
476
|
+
label_len = [parent_label.length, child_label.length].max
|
477
|
+
|
478
|
+
@logger.warn(<<-EOS % [label_len, parent_label, label_len, child_label])
|
479
|
+
[WARNING] Relation column type is different.
|
480
|
+
%*s: #{pk_type}
|
481
|
+
%*s: #{child_column_type}
|
482
|
+
EOS
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
422
487
|
end
|
data/lib/ridgepole/version.rb
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate', 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", 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.integer "employee_id"
|
26
|
+
t.string "dept_no", limit: 4, null: false
|
27
|
+
t.date "from_date", null: false
|
28
|
+
t.date "to_date", null: false
|
29
|
+
end
|
30
|
+
|
31
|
+
create_table "employees", 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: 'bigint') }
|
44
|
+
|
45
|
+
it {
|
46
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
|
47
|
+
[WARNING] Relation column type is different.
|
48
|
+
employees.id: bigint
|
49
|
+
dept_manager.employee_id: 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 'without 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", 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", 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_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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridgepole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.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: 2017-06-
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -284,6 +284,7 @@ files:
|
|
284
284
|
- spec/mysql/migrate/migrate_change_index7_spec.rb
|
285
285
|
- spec/mysql/migrate/migrate_change_index_spec.rb
|
286
286
|
- spec/mysql/migrate/migrate_change_table_option_spec.rb
|
287
|
+
- spec/mysql/migrate/migrate_check_relation_column_type_spec.rb
|
287
288
|
- spec/mysql/migrate/migrate_create_index2_spec.rb
|
288
289
|
- spec/mysql/migrate/migrate_create_index_spec.rb
|
289
290
|
- spec/mysql/migrate/migrate_create_table_spec.rb
|
@@ -425,6 +426,7 @@ test_files:
|
|
425
426
|
- spec/mysql/migrate/migrate_change_index7_spec.rb
|
426
427
|
- spec/mysql/migrate/migrate_change_index_spec.rb
|
427
428
|
- spec/mysql/migrate/migrate_change_table_option_spec.rb
|
429
|
+
- spec/mysql/migrate/migrate_check_relation_column_type_spec.rb
|
428
430
|
- spec/mysql/migrate/migrate_create_index2_spec.rb
|
429
431
|
- spec/mysql/migrate/migrate_create_index_spec.rb
|
430
432
|
- spec/mysql/migrate/migrate_create_table_spec.rb
|