ridgepole 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/ridgepole/diff.rb +1 -1
- data/lib/ridgepole/dsl_parser.rb +10 -2
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +1 -1
- data/spec/migrate/migrate_change_table_option_spec.rb +40 -0
- data/spec/migrate/migrate_duplicate_index_spec.rb +25 -0
- data/spec/migrate/migrate_duplicate_table_spec.rb +35 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b78450efbe8c650197b9515c90abced3f6a6575
|
4
|
+
data.tar.gz: 4e78c9e6a877414d75d58735ad8ebd2c0b2d090f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8be2793d3f8bc2f8083c5c50805dc180cec3e0ce451203d74f678f601aa2f24c5225d0fe0b81d142ba87bf40d879f9c54cbe7547c2af14612ec9ea4d451a3459
|
7
|
+
data.tar.gz: f8e0160bb8ade13201edf404c30278705ec9d8fad1b2d3cbd6390b8739db82b6754ef6eda4ca281da7a6196b847d931299961f1a2b972754f736c8b1ec1f36b4
|
data/README.md
CHANGED
@@ -34,3 +34,9 @@ ridgepole --apply
|
|
34
34
|
## Demo
|
35
35
|
|
36
36
|
* [asciinema.org/a/9349](https://asciinema.org/a/9349)
|
37
|
+
|
38
|
+
## Example project
|
39
|
+
|
40
|
+
* https://github.com/winebarrel/ridgepole-example
|
41
|
+
* https://github.com/winebarrel/ridgepole-example/pull/1
|
42
|
+
* https://github.com/winebarrel/ridgepole-example/pull/2
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -61,7 +61,7 @@ class Ridgepole::Diff
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def scan_options_change(from, to, table_delta)
|
64
|
-
|
64
|
+
Ridgepole::Logger.instance.warn('[WARNING] Table options cannot be changed')
|
65
65
|
end
|
66
66
|
|
67
67
|
def scan_definition_change(from, to, table_delta)
|
data/lib/ridgepole/dsl_parser.rb
CHANGED
@@ -51,20 +51,28 @@ class Ridgepole::DSLParser
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def create_table(table_name, options = {})
|
54
|
-
# XXX: Add exist check
|
55
54
|
table_definition = TableDefinition.new
|
56
55
|
yield(table_definition)
|
57
56
|
@__definition[table_name] ||= {}
|
57
|
+
|
58
|
+
if @__definition[table_name][:definition]
|
59
|
+
raise "Table `#{table_name}` already defined"
|
60
|
+
end
|
61
|
+
|
58
62
|
@__definition[table_name][:definition] = table_definition.__definition
|
59
63
|
options.delete(:force)
|
60
64
|
@__definition[table_name][:options] = options
|
61
65
|
end
|
62
66
|
|
63
67
|
def add_index(table_name, column_name, options = {})
|
64
|
-
# XXX: Add exist check
|
65
68
|
@__definition[table_name] ||= {}
|
66
69
|
@__definition[table_name][:indices] ||= {}
|
67
70
|
idx = options[:name] || column_name
|
71
|
+
|
72
|
+
if @__definition[table_name][:indices][idx]
|
73
|
+
raise "Index `#{table_name}(#{idx})` already defined"
|
74
|
+
end
|
75
|
+
|
68
76
|
@__definition[table_name][:indices][idx] = {
|
69
77
|
:column_name => column_name,
|
70
78
|
:options => options,
|
data/lib/ridgepole/version.rb
CHANGED
data/ridgepole.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['sugawara@cookpad.com']
|
11
11
|
spec.summary = %q{Ridgepole is a tool to DB schema.}
|
12
12
|
spec.description = %q{Ridgepole is a tool to DB schema. It defines DB schema using Rails DSL, and updates DB schema according to DSL.}
|
13
|
-
spec.homepage = 'https://
|
13
|
+
spec.homepage = 'https://github.com/winebarrel/ridgepole'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -0,0 +1,40 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when change column' 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", null: false
|
11
|
+
end
|
12
|
+
|
13
|
+
RUBY
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:expected_dsl) {
|
17
|
+
<<-RUBY
|
18
|
+
create_table "employees", primary_key: "emp_no2", force: true do |t|
|
19
|
+
t.date "birth_date", null: false
|
20
|
+
t.string "first_name", limit: 14, null: false
|
21
|
+
t.string "last_name", limit: 16, null: false
|
22
|
+
t.string "gender", limit: 1, null: false
|
23
|
+
t.date "hire_date", null: false
|
24
|
+
end
|
25
|
+
RUBY
|
26
|
+
}
|
27
|
+
|
28
|
+
before { subject.diff(actual_dsl).migrate }
|
29
|
+
subject { client }
|
30
|
+
|
31
|
+
it {
|
32
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with('[WARNING] Table options cannot be changed')
|
33
|
+
delta = subject.diff(expected_dsl)
|
34
|
+
expect(delta.differ?).to be_false
|
35
|
+
expect(subject.dump).to eq actual_dsl.undent.strip
|
36
|
+
delta.migrate
|
37
|
+
expect(subject.dump).to eq actual_dsl.undent.strip
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when index already defined' do
|
3
|
+
let(:dsl) {
|
4
|
+
<<-RUBY
|
5
|
+
create_table "salaries", id: false, force: true do |t|
|
6
|
+
t.integer "emp_no", null: false
|
7
|
+
t.integer "salary", null: false
|
8
|
+
t.date "from_date", null: false
|
9
|
+
t.date "to_date", null: false
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
13
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
14
|
+
RUBY
|
15
|
+
}
|
16
|
+
|
17
|
+
subject { client }
|
18
|
+
|
19
|
+
it {
|
20
|
+
expect {
|
21
|
+
subject.diff(dsl)
|
22
|
+
}.to raise_error('Index `salaries(emp_no)` already defined')
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when table already defined' do
|
3
|
+
let(: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", null: false
|
11
|
+
t.integer "age", unsigned: true, null: false
|
12
|
+
t.date "updated_at"
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
16
|
+
t.date "birth_date", null: false
|
17
|
+
t.string "first_name", limit: 14, null: false
|
18
|
+
t.string "last_name", limit: 16, null: false
|
19
|
+
t.string "gender", limit: 1, null: false
|
20
|
+
t.date "hire_date", null: false
|
21
|
+
t.integer "age", unsigned: true, null: false
|
22
|
+
t.date "updated_at"
|
23
|
+
end
|
24
|
+
RUBY
|
25
|
+
}
|
26
|
+
|
27
|
+
subject { client }
|
28
|
+
|
29
|
+
it {
|
30
|
+
expect {
|
31
|
+
subject.diff(dsl)
|
32
|
+
}.to raise_error('Table `employees` already defined')
|
33
|
+
}
|
34
|
+
end
|
35
|
+
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -127,11 +127,14 @@ files:
|
|
127
127
|
- spec/dump/dump_spec.rb
|
128
128
|
- spec/migrate/migrate_add_column_spec.rb
|
129
129
|
- spec/migrate/migrate_change_column_spec.rb
|
130
|
+
- spec/migrate/migrate_change_table_option_spec.rb
|
130
131
|
- spec/migrate/migrate_create_index_spec.rb
|
131
132
|
- spec/migrate/migrate_create_table_spec.rb
|
132
133
|
- spec/migrate/migrate_drop_column_spec.rb
|
133
134
|
- spec/migrate/migrate_drop_index.rb
|
134
135
|
- spec/migrate/migrate_drop_table.rb
|
136
|
+
- spec/migrate/migrate_duplicate_index_spec.rb
|
137
|
+
- spec/migrate/migrate_duplicate_table_spec.rb
|
135
138
|
- spec/migrate/migrate_empty_spec.rb
|
136
139
|
- spec/migrate/migrate_merge_mode_spec.rb
|
137
140
|
- spec/migrate/migrate_rename_column_spec.rb
|
@@ -143,7 +146,7 @@ files:
|
|
143
146
|
- spec/ridgepole_test_tables.sql
|
144
147
|
- spec/spec_helper.rb
|
145
148
|
- spec/string_ext.rb
|
146
|
-
homepage: https://
|
149
|
+
homepage: https://github.com/winebarrel/ridgepole
|
147
150
|
licenses:
|
148
151
|
- MIT
|
149
152
|
metadata: {}
|
@@ -173,11 +176,14 @@ test_files:
|
|
173
176
|
- spec/dump/dump_spec.rb
|
174
177
|
- spec/migrate/migrate_add_column_spec.rb
|
175
178
|
- spec/migrate/migrate_change_column_spec.rb
|
179
|
+
- spec/migrate/migrate_change_table_option_spec.rb
|
176
180
|
- spec/migrate/migrate_create_index_spec.rb
|
177
181
|
- spec/migrate/migrate_create_table_spec.rb
|
178
182
|
- spec/migrate/migrate_drop_column_spec.rb
|
179
183
|
- spec/migrate/migrate_drop_index.rb
|
180
184
|
- spec/migrate/migrate_drop_table.rb
|
185
|
+
- spec/migrate/migrate_duplicate_index_spec.rb
|
186
|
+
- spec/migrate/migrate_duplicate_table_spec.rb
|
181
187
|
- spec/migrate/migrate_empty_spec.rb
|
182
188
|
- spec/migrate/migrate_merge_mode_spec.rb
|
183
189
|
- spec/migrate/migrate_rename_column_spec.rb
|