ridgepole 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/ridgepole +2 -0
- data/lib/ridgepole/delta.rb +27 -3
- data/lib/ridgepole/version.rb +1 -1
- data/spec/migrate/migrate_with_pre_post_query_spec.rb +165 -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: 04ff9c0b5b25d5bed40e085992ae9f4a605381e6
|
4
|
+
data.tar.gz: 799269ed647277c33317a16596cbb068498592d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6717299b01c508286c13ee9dffcfcfb5cc6066a4629de48a0f7000bdcc2b6059b4a480dc7589307036c7fd5eb7be6cb0f761db8b738dc8a54e47b8be60054da4
|
7
|
+
data.tar.gz: 4a82f7ae17dcbdafd2748f22142bdf5986d4005bb7ca6400dd0a57a13e0543c4f4f4cf51f0e14aa5bf27ca14029424221fe4234984f8a739adab64c3ea362ae2
|
data/README.md
CHANGED
data/bin/ridgepole
CHANGED
@@ -51,6 +51,8 @@ ARGV.options do |opt|
|
|
51
51
|
raise "Cannot use `bulk-change` in `merge`" if options[:merge]
|
52
52
|
options[:bulk_change] = true
|
53
53
|
}
|
54
|
+
opt.on('', '--pre-query QUERY') {|v| options[:pre_query] = v }
|
55
|
+
opt.on('', '--post-query QUERY') {|v| options[:post_query] = v }
|
54
56
|
opt.on('-e', '--export') { set_mode[:export] }
|
55
57
|
opt.on('', '--split') {|v| split = true }
|
56
58
|
opt.on('', '--split-with-dir') {|v| split = :with_dir }
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -59,7 +59,7 @@ class Ridgepole::Delta
|
|
59
59
|
end
|
60
60
|
|
61
61
|
Ridgepole::ExecuteExpander.without_operation(callback) do
|
62
|
-
eval_script(script)
|
62
|
+
eval_script(script, buf)
|
63
63
|
end
|
64
64
|
|
65
65
|
buf.string.strip
|
@@ -71,14 +71,38 @@ class Ridgepole::Delta
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def eval_script(script)
|
74
|
+
def eval_script(script, out = $stdout)
|
75
75
|
begin
|
76
|
-
|
76
|
+
with_pre_post_query(out) do
|
77
|
+
ActiveRecord::Schema.new.instance_eval(script, SCRIPT_NAME, 1)
|
78
|
+
end
|
77
79
|
rescue => e
|
78
80
|
raise_exception(script, e)
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
84
|
+
def with_pre_post_query(out = $stdout)
|
85
|
+
if (pre_query = @options[:pre_query])
|
86
|
+
if @options[:noop]
|
87
|
+
out.puts(pre_query)
|
88
|
+
else
|
89
|
+
ActiveRecord::Base.connection.execute(pre_query)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
retval = yield
|
94
|
+
|
95
|
+
if (post_query = @options[:post_query])
|
96
|
+
if @options[:noop]
|
97
|
+
out.puts(post_query)
|
98
|
+
else
|
99
|
+
ActiveRecord::Base.connection.execute(post_query)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
return retval
|
104
|
+
end
|
105
|
+
|
82
106
|
def raise_exception(script, org)
|
83
107
|
lines = script.each_line
|
84
108
|
digit_number = (lines.count + 1).to_s.length
|
data/lib/ridgepole/version.rb
CHANGED
@@ -0,0 +1,165 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'migrate with pre/post query' do
|
3
|
+
let(:actual_dsl) { '' }
|
4
|
+
let(:dsl) {
|
5
|
+
<<-RUBY
|
6
|
+
create_table "clubs", force: true do |t|
|
7
|
+
t.string "name", default: "", null: false
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
11
|
+
|
12
|
+
create_table "departments", primary_key: "dept_no", force: true do |t|
|
13
|
+
t.string "dept_name", limit: 40, null: false
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
|
17
|
+
|
18
|
+
create_table "dept_emp", id: false, force: true do |t|
|
19
|
+
t.integer "emp_no", null: false
|
20
|
+
t.string "dept_no", limit: 4, null: false
|
21
|
+
t.date "from_date", null: false
|
22
|
+
t.date "to_date", null: false
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
|
26
|
+
add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
|
27
|
+
|
28
|
+
create_table "dept_manager", id: false, force: true do |t|
|
29
|
+
t.string "dept_no", limit: 4, null: false
|
30
|
+
t.integer "emp_no", null: false
|
31
|
+
t.date "from_date", null: false
|
32
|
+
t.date "to_date", null: false
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
36
|
+
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
37
|
+
|
38
|
+
create_table "employee_clubs", force: true do |t|
|
39
|
+
t.integer "emp_no", unsigned: true, null: false
|
40
|
+
t.integer "club_id", unsigned: true, null: false
|
41
|
+
end
|
42
|
+
|
43
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
44
|
+
|
45
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
46
|
+
t.date "birth_date", null: false
|
47
|
+
t.string "first_name", limit: 14, null: false
|
48
|
+
t.string "last_name", limit: 16, null: false
|
49
|
+
t.string "gender", limit: 1, null: false
|
50
|
+
t.date "hire_date", null: false
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table "salaries", id: false, force: true do |t|
|
54
|
+
t.integer "emp_no", null: false
|
55
|
+
t.integer "salary", null: false
|
56
|
+
t.date "from_date", null: false
|
57
|
+
t.date "to_date", null: false
|
58
|
+
end
|
59
|
+
|
60
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
61
|
+
|
62
|
+
create_table "titles", id: false, force: true do |t|
|
63
|
+
t.integer "emp_no", null: false
|
64
|
+
t.string "title", limit: 50, null: false
|
65
|
+
t.date "from_date", null: false
|
66
|
+
t.date "to_date"
|
67
|
+
end
|
68
|
+
|
69
|
+
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
70
|
+
RUBY
|
71
|
+
}
|
72
|
+
|
73
|
+
let(:expected_dsl) {
|
74
|
+
<<-RUBY
|
75
|
+
create_table "clubs", force: true do |t|
|
76
|
+
t.string "name", default: "", null: false
|
77
|
+
end
|
78
|
+
|
79
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
80
|
+
|
81
|
+
create_table "departments", primary_key: "dept_no", force: true do |t|
|
82
|
+
t.string "dept_name", limit: 40, null: false
|
83
|
+
end
|
84
|
+
|
85
|
+
add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
|
86
|
+
|
87
|
+
create_table "dept_emp", id: false, force: true do |t|
|
88
|
+
t.integer "emp_no", null: false
|
89
|
+
t.string "dept_no", limit: 4, null: false
|
90
|
+
t.date "from_date", null: false
|
91
|
+
t.date "to_date", null: false
|
92
|
+
end
|
93
|
+
|
94
|
+
add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
|
95
|
+
add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
|
96
|
+
|
97
|
+
create_table "dept_manager", id: false, force: true do |t|
|
98
|
+
t.string "dept_no", limit: 4, null: false
|
99
|
+
t.integer "emp_no", null: false
|
100
|
+
t.date "from_date", null: false
|
101
|
+
t.date "to_date", null: false
|
102
|
+
end
|
103
|
+
|
104
|
+
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
105
|
+
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
106
|
+
|
107
|
+
create_table "employee_clubs", force: true do |t|
|
108
|
+
t.integer "emp_no", unsigned: true, null: false
|
109
|
+
t.integer "club_id", unsigned: true, null: false
|
110
|
+
end
|
111
|
+
|
112
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
113
|
+
|
114
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
115
|
+
t.date "birth_date", null: false
|
116
|
+
t.string "first_name", limit: 14, null: false
|
117
|
+
t.string "last_name", limit: 16, null: false
|
118
|
+
t.string "gender", limit: 1, null: false
|
119
|
+
t.date "hire_date", null: false
|
120
|
+
end
|
121
|
+
|
122
|
+
create_table "post", id: false, force: true do |t|
|
123
|
+
t.integer "id"
|
124
|
+
end
|
125
|
+
|
126
|
+
create_table "pre", id: false, force: true do |t|
|
127
|
+
t.integer "id"
|
128
|
+
end
|
129
|
+
|
130
|
+
create_table "salaries", id: false, force: true do |t|
|
131
|
+
t.integer "emp_no", null: false
|
132
|
+
t.integer "salary", null: false
|
133
|
+
t.date "from_date", null: false
|
134
|
+
t.date "to_date", null: false
|
135
|
+
end
|
136
|
+
|
137
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
138
|
+
|
139
|
+
create_table "titles", id: false, force: true do |t|
|
140
|
+
t.integer "emp_no", null: false
|
141
|
+
t.string "title", limit: 50, null: false
|
142
|
+
t.date "from_date", null: false
|
143
|
+
t.date "to_date"
|
144
|
+
end
|
145
|
+
|
146
|
+
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
147
|
+
RUBY
|
148
|
+
}
|
149
|
+
|
150
|
+
subject {
|
151
|
+
client(
|
152
|
+
:pre_query => 'create table pre (id int)',
|
153
|
+
:post_query => 'create table post (id int)',
|
154
|
+
)
|
155
|
+
}
|
156
|
+
|
157
|
+
it {
|
158
|
+
delta = subject.diff(dsl)
|
159
|
+
expect(delta.differ?).to be_truthy
|
160
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
161
|
+
delta.migrate
|
162
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
163
|
+
}
|
164
|
+
end
|
165
|
+
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.3.
|
4
|
+
version: 0.3.7
|
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-08-
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- spec/migrate/migrate_skip_rename_column_spec.rb
|
156
156
|
- spec/migrate/migrate_skip_rename_table_spec.rb
|
157
157
|
- spec/migrate/migrate_with_ignore_tables_spec.rb
|
158
|
+
- spec/migrate/migrate_with_pre_post_query_spec.rb
|
158
159
|
- spec/migrate/migrate_with_tables_spec.rb
|
159
160
|
- spec/ridgepole_test_database.sql
|
160
161
|
- spec/ridgepole_test_tables.sql
|
@@ -217,6 +218,7 @@ test_files:
|
|
217
218
|
- spec/migrate/migrate_skip_rename_column_spec.rb
|
218
219
|
- spec/migrate/migrate_skip_rename_table_spec.rb
|
219
220
|
- spec/migrate/migrate_with_ignore_tables_spec.rb
|
221
|
+
- spec/migrate/migrate_with_pre_post_query_spec.rb
|
220
222
|
- spec/migrate/migrate_with_tables_spec.rb
|
221
223
|
- spec/ridgepole_test_database.sql
|
222
224
|
- spec/ridgepole_test_tables.sql
|