ridgepole 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab3d1415ea667dc38d7e9e3a039fa2faefab3e4c
|
4
|
+
data.tar.gz: 98097987a640fba886daf5b82202c7198576e655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf3b70e23223126228023ebe3cd075711aec5c184422b1617e2b856da9ae710147c0a497d54311a1893bd0a032fe3856dd953b7130ee39bb1e3ee0f3d0485536
|
7
|
+
data.tar.gz: 4149d78aa6421566d07f2b2e6c2e19cd60b611d7f880776bf5b03faf2931a95dbfefefc456641a3d49bf93a4d7c39890cbb8ecdb31c6cac75781c35d36f51c98
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -83,6 +83,9 @@ class Ridgepole::Diff
|
|
83
83
|
|
84
84
|
to.each do |column_name, to_attrs|
|
85
85
|
if (from_attrs = from.delete(column_name))
|
86
|
+
normalize_column_options!(from_attrs[:options])
|
87
|
+
normalize_column_options!(to_attrs[:options])
|
88
|
+
|
86
89
|
if from_attrs != to_attrs
|
87
90
|
definition_delta[:change] ||= {}
|
88
91
|
definition_delta[:change][column_name] = to_attrs
|
@@ -152,4 +155,12 @@ class Ridgepole::Diff
|
|
152
155
|
def target?(table_name)
|
153
156
|
not @options[:tables] or @options[:tables].include?(table_name)
|
154
157
|
end
|
158
|
+
|
159
|
+
def normalize_column_options!(opts)
|
160
|
+
opts[:null] = true unless opts.has_key?(:null)
|
161
|
+
|
162
|
+
unless @options[:disable_mysql_unsigned]
|
163
|
+
opts[:unsigned] = false unless opts.has_key?(:unsigned)
|
164
|
+
end
|
165
|
+
end
|
155
166
|
end
|
data/lib/ridgepole/version.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
describe 'Ridgepole::Client#dump' do
|
2
|
+
context 'when there is a tables (disable unsigned)' do
|
3
|
+
before { restore_tables }
|
4
|
+
subject { client(disable_mysql_unsigned: true) }
|
5
|
+
|
6
|
+
it {
|
7
|
+
expect(subject.dump).to eq (<<-RUBY).undent.strip
|
8
|
+
create_table "clubs", force: true do |t|
|
9
|
+
t.string "name", default: "", null: false
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
13
|
+
|
14
|
+
create_table "departments", primary_key: "dept_no", force: true do |t|
|
15
|
+
t.string "dept_name", limit: 40, null: false
|
16
|
+
end
|
17
|
+
|
18
|
+
add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
|
19
|
+
|
20
|
+
create_table "dept_emp", id: false, force: true do |t|
|
21
|
+
t.integer "emp_no", null: false
|
22
|
+
t.string "dept_no", limit: 4, null: false
|
23
|
+
t.date "from_date", null: false
|
24
|
+
t.date "to_date", null: false
|
25
|
+
end
|
26
|
+
|
27
|
+
add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
|
28
|
+
add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
|
29
|
+
|
30
|
+
create_table "dept_manager", id: false, force: true do |t|
|
31
|
+
t.string "dept_no", limit: 4, null: false
|
32
|
+
t.integer "emp_no", null: false
|
33
|
+
t.date "from_date", null: false
|
34
|
+
t.date "to_date", null: false
|
35
|
+
end
|
36
|
+
|
37
|
+
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
38
|
+
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
39
|
+
|
40
|
+
create_table "employee_clubs", force: true do |t|
|
41
|
+
t.integer "emp_no", null: false
|
42
|
+
t.integer "club_id", null: false
|
43
|
+
end
|
44
|
+
|
45
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
46
|
+
|
47
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
48
|
+
t.date "birth_date", null: false
|
49
|
+
t.string "first_name", limit: 14, null: false
|
50
|
+
t.string "last_name", limit: 16, null: false
|
51
|
+
t.string "gender", limit: 1, null: false
|
52
|
+
t.date "hire_date", null: false
|
53
|
+
end
|
54
|
+
|
55
|
+
create_table "salaries", id: false, force: true do |t|
|
56
|
+
t.integer "emp_no", null: false
|
57
|
+
t.integer "salary", null: false
|
58
|
+
t.date "from_date", null: false
|
59
|
+
t.date "to_date", null: false
|
60
|
+
end
|
61
|
+
|
62
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
63
|
+
|
64
|
+
create_table "titles", id: false, force: true do |t|
|
65
|
+
t.integer "emp_no", null: false
|
66
|
+
t.string "title", limit: 50, null: false
|
67
|
+
t.date "from_date", null: false
|
68
|
+
t.date "to_date"
|
69
|
+
end
|
70
|
+
|
71
|
+
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
72
|
+
RUBY
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when database and definition are same (default null / nothing -> null:true)' do
|
3
|
+
let(:actual_dsl) {
|
4
|
+
<<-RUBY
|
5
|
+
create_table "employees", primary_key: "emp_no", force: true 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"
|
11
|
+
end
|
12
|
+
RUBY
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:expected_dsl) {
|
16
|
+
<<-RUBY
|
17
|
+
create_table "employees", primary_key: "emp_no", force: true 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 "gender", limit: 1, null: false
|
22
|
+
t.date "hire_date", null: true
|
23
|
+
end
|
24
|
+
RUBY
|
25
|
+
}
|
26
|
+
|
27
|
+
before { subject.diff(actual_dsl).migrate }
|
28
|
+
subject { client }
|
29
|
+
|
30
|
+
it {
|
31
|
+
delta = subject.diff(expected_dsl)
|
32
|
+
expect(delta.differ?).to be_false
|
33
|
+
expect(subject.dump).to eq actual_dsl.undent.strip
|
34
|
+
delta.migrate
|
35
|
+
expect(subject.dump).to eq expected_dsl.undent.strip.gsub(/\s*,\s*null: true/, '')
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when database and definition are same (default null / null:true -> nothing)' do
|
40
|
+
let(:actual_dsl) {
|
41
|
+
<<-RUBY
|
42
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
43
|
+
t.date "birth_date", null: false
|
44
|
+
t.string "first_name", limit: 14, null: false
|
45
|
+
t.string "last_name", limit: 16, null: false
|
46
|
+
t.string "gender", limit: 1, null: false
|
47
|
+
t.date "hire_date", null: true
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
}
|
51
|
+
|
52
|
+
let(:expected_dsl) {
|
53
|
+
<<-RUBY
|
54
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
55
|
+
t.date "birth_date", null: false
|
56
|
+
t.string "first_name", limit: 14, null: false
|
57
|
+
t.string "last_name", limit: 16, null: false
|
58
|
+
t.string "gender", limit: 1, null: false
|
59
|
+
t.date "hire_date"
|
60
|
+
end
|
61
|
+
RUBY
|
62
|
+
}
|
63
|
+
|
64
|
+
before { subject.diff(actual_dsl).migrate }
|
65
|
+
subject { client }
|
66
|
+
|
67
|
+
it {
|
68
|
+
delta = subject.diff(expected_dsl)
|
69
|
+
expect(delta.differ?).to be_false
|
70
|
+
expect(subject.dump).to eq actual_dsl.undent.strip.gsub(/\s*,\s*null: true/, '')
|
71
|
+
delta.migrate
|
72
|
+
expect(subject.dump).to eq expected_dsl.undent.strip
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when database and definition are same (default unsigned / nothing -> unsigned:false)' do
|
3
|
+
let(:actual_dsl) {
|
4
|
+
<<-RUBY
|
5
|
+
create_table "employee_clubs", force: true do |t|
|
6
|
+
t.integer "emp_no", unsigned: true, null: false
|
7
|
+
t.integer "club_id", null: false
|
8
|
+
end
|
9
|
+
RUBY
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:expected_dsl) {
|
13
|
+
<<-RUBY
|
14
|
+
create_table "employee_clubs", force: true do |t|
|
15
|
+
t.integer "emp_no", unsigned: true, null: false
|
16
|
+
t.integer "club_id", unsigned: false,null: false
|
17
|
+
end
|
18
|
+
RUBY
|
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_false
|
27
|
+
expect(subject.dump).to eq actual_dsl.undent.strip
|
28
|
+
delta.migrate
|
29
|
+
expect(subject.dump).to eq expected_dsl.undent.strip.gsub('unsigned: false,', ' ')
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when database and definition are same (default null / unsigned:false -> nothing)' do
|
34
|
+
let(:actual_dsl) {
|
35
|
+
<<-RUBY
|
36
|
+
create_table "employee_clubs", force: true do |t|
|
37
|
+
t.integer "emp_no", unsigned: true, null: false
|
38
|
+
t.integer "club_id", unsigned: false,null: false
|
39
|
+
end
|
40
|
+
RUBY
|
41
|
+
}
|
42
|
+
|
43
|
+
let(:expected_dsl) {
|
44
|
+
<<-RUBY
|
45
|
+
create_table "employee_clubs", force: true do |t|
|
46
|
+
t.integer "emp_no", unsigned: true, null: false
|
47
|
+
t.integer "club_id", null: false
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
}
|
51
|
+
|
52
|
+
before { subject.diff(actual_dsl).migrate }
|
53
|
+
subject { client }
|
54
|
+
|
55
|
+
it {
|
56
|
+
delta = subject.diff(expected_dsl)
|
57
|
+
expect(delta.differ?).to be_false
|
58
|
+
expect(subject.dump).to eq actual_dsl.undent.strip.gsub('unsigned: false,', ' ')
|
59
|
+
delta.migrate
|
60
|
+
expect(subject.dump).to eq expected_dsl.undent.strip
|
61
|
+
}
|
62
|
+
end
|
63
|
+
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/ridgepole/string_ext.rb
|
121
121
|
- lib/ridgepole/version.rb
|
122
122
|
- ridgepole.gemspec
|
123
|
+
- spec/dump/dump_disable_unsigned_spec.rb
|
123
124
|
- spec/dump/dump_spec.rb
|
124
125
|
- spec/migrate/migrate_add_column_spec.rb
|
125
126
|
- spec/migrate/migrate_change_column_spec.rb
|
@@ -132,6 +133,8 @@ files:
|
|
132
133
|
- spec/migrate/migrate_merge_mode_spec.rb
|
133
134
|
- spec/migrate/migrate_rename_column_spec.rb
|
134
135
|
- spec/migrate/migrate_rename_table_spec.rb
|
136
|
+
- spec/migrate/migrate_same_default_null_spec.rb
|
137
|
+
- spec/migrate/migrate_same_default_unsigned_spec.rb
|
135
138
|
- spec/migrate/migrate_same_spec.rb
|
136
139
|
- spec/ridgepole_test_database.sql
|
137
140
|
- spec/ridgepole_test_tables.sql
|
@@ -162,6 +165,7 @@ signing_key:
|
|
162
165
|
specification_version: 4
|
163
166
|
summary: Ridgepole is a tool to DB schema.
|
164
167
|
test_files:
|
168
|
+
- spec/dump/dump_disable_unsigned_spec.rb
|
165
169
|
- spec/dump/dump_spec.rb
|
166
170
|
- spec/migrate/migrate_add_column_spec.rb
|
167
171
|
- spec/migrate/migrate_change_column_spec.rb
|
@@ -174,6 +178,8 @@ test_files:
|
|
174
178
|
- spec/migrate/migrate_merge_mode_spec.rb
|
175
179
|
- spec/migrate/migrate_rename_column_spec.rb
|
176
180
|
- spec/migrate/migrate_rename_table_spec.rb
|
181
|
+
- spec/migrate/migrate_same_default_null_spec.rb
|
182
|
+
- spec/migrate/migrate_same_default_unsigned_spec.rb
|
177
183
|
- spec/migrate/migrate_same_spec.rb
|
178
184
|
- spec/ridgepole_test_database.sql
|
179
185
|
- spec/ridgepole_test_tables.sql
|