duck_duck_duck 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/duck_duck_duck.rb +35 -17
- data/specs/duck_duck_duck.rb +32 -0
- data/specs/lib/models/0030_model/migrates/0010-table.sql +6 -4
- data/specs/lib/models/0040_model/migrates/0010-table.sql +14 -0
- data/specs/lib/models/0040_model/migrates/__-insert-1.sql +16 -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: fc9d363fc3f2add54ba7cc80a1f272fffd6ad9fe
|
4
|
+
data.tar.gz: becb37dc9a4644a240d85115f1bdd59d6b7ced6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f8e635b02307254b949e69967d07b689a6c1e5c919ad24fcbce22f3ec78397652e7f9929038fbe98c3b65e3485fcc605aa49adba0c61f4ff7ba3220281c9574
|
7
|
+
data.tar.gz: b3a25e2d1cf9ec7a7544e2ec2a6f6a82343e8c22e7a5e5b3b8d843992a6349f635be4df266d0bee276afeb4f57e5528fcbafbe363448a37f77ff2fd1d5717bdb
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.2.0
|
data/lib/duck_duck_duck.rb
CHANGED
@@ -74,11 +74,18 @@ class Duck_Duck_Duck
|
|
74
74
|
fail ArgumentError, "Name required."
|
75
75
|
end
|
76
76
|
|
77
|
-
@
|
77
|
+
@__files = `find . -iregex ".+/#{name}/migrates/__.+\.sql"`
|
78
78
|
.strip
|
79
79
|
.split("\n")
|
80
|
-
.grep(/\/\d+\-/)
|
81
80
|
.sort
|
81
|
+
|
82
|
+
@files = (
|
83
|
+
`find . -iregex ".+/#{name}/migrates/.+\.sql"`
|
84
|
+
.strip
|
85
|
+
.split("\n")
|
86
|
+
.grep(/\/\d+\-/)
|
87
|
+
.sort
|
88
|
+
)
|
82
89
|
end
|
83
90
|
|
84
91
|
def stdout *args
|
@@ -130,6 +137,15 @@ class Duck_Duck_Duck
|
|
130
137
|
end
|
131
138
|
}.compact
|
132
139
|
|
140
|
+
if @__files.empty? && files.empty?
|
141
|
+
stdout "#{name} is already the latest: #{rec[:version]}"
|
142
|
+
end
|
143
|
+
|
144
|
+
@__files.each { |f|
|
145
|
+
DB << Duck_Duck_Duck.read_file(f)[:UP]
|
146
|
+
stdout "ran file: #{f}"
|
147
|
+
}
|
148
|
+
|
133
149
|
files.each { |pair|
|
134
150
|
ver = pair.first
|
135
151
|
sql = pair[1]
|
@@ -138,32 +154,29 @@ class Duck_Duck_Duck
|
|
138
154
|
stdout "#{name} schema is now : #{ver}"
|
139
155
|
}
|
140
156
|
|
141
|
-
if files.empty?
|
142
|
-
stdout "#{name} is already the latest: #{rec[:version]}"
|
143
|
-
end
|
144
157
|
end # === def up
|
145
158
|
|
146
159
|
def down
|
147
160
|
rec = init_model_in_schema
|
148
161
|
|
149
|
-
if rec[:version] == 0
|
150
|
-
stdout "#{name} is already the latest: #{rec[:version]}\n"
|
151
|
-
exit 0
|
152
|
-
end
|
153
|
-
|
154
162
|
if rec[:version] < 0
|
155
163
|
stdout "#{name} is at invalid version: #{rec[:version]}\n"
|
156
164
|
exit 1
|
157
165
|
end
|
158
166
|
|
159
|
-
files =
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
167
|
+
files = if rec[:version] == 0
|
168
|
+
[]
|
169
|
+
else
|
170
|
+
@files.sort.reverse.map { |f|
|
171
|
+
ver = file_to_ver(f)
|
172
|
+
next unless ver <= rec[:version]
|
173
|
+
[ ver, Duck_Duck_Duck.read_file(f)[:DOWN] ]
|
174
|
+
}.compact
|
175
|
+
end
|
176
|
+
|
177
|
+
if @__files.empty? && files.empty?
|
166
178
|
stdout "#{name} is already the latest: #{rec[:version]}\n"
|
179
|
+
exit 0
|
167
180
|
end
|
168
181
|
|
169
182
|
new_ver = nil
|
@@ -177,6 +190,11 @@ class Duck_Duck_Duck
|
|
177
190
|
stdout "#{name} schema is now : #{ver}"
|
178
191
|
}
|
179
192
|
|
193
|
+
@__files.reverse.each { |f|
|
194
|
+
DB << Duck_Duck_Duck.read_file(f)[:DOWN]
|
195
|
+
stdout "down: #{f}"
|
196
|
+
}
|
197
|
+
|
180
198
|
end # === def down
|
181
199
|
|
182
200
|
def create
|
data/specs/duck_duck_duck.rb
CHANGED
@@ -193,4 +193,36 @@ describe '-- UP/-- DOWN model' do
|
|
193
193
|
|
194
194
|
end # === describe '-- UP/-- DOWN model'
|
195
195
|
|
196
|
+
describe '__-...sql files' do
|
197
|
+
|
198
|
+
before { reset }
|
199
|
+
|
200
|
+
it "runs file on each migrate up" do
|
201
|
+
Exit_0("duck_duck_duck up 0040_model")
|
202
|
+
Exit_0("duck_duck_duck up 0040_model")
|
203
|
+
Exit_0("duck_duck_duck up 0040_model")
|
204
|
+
get(%^SELECT title FROM "0040_model"^).
|
205
|
+
should == [
|
206
|
+
{:title=>"__ up"},
|
207
|
+
{:title=>"CREATE 0040_model"},
|
208
|
+
{:title=>"__ up"},
|
209
|
+
{:title=>"__ up"}
|
210
|
+
]
|
211
|
+
end # === it
|
212
|
+
|
213
|
+
it "runs file on each migrate down" do
|
214
|
+
Exit_0("duck_duck_duck up 0040_model")
|
215
|
+
Exit_0("duck_duck_duck down 0040_model")
|
216
|
+
Exit_0("duck_duck_duck down 0040_model")
|
217
|
+
get(%^SELECT title FROM "0040_model"^).
|
218
|
+
should == [
|
219
|
+
{:title=>"__ up"},
|
220
|
+
{:title=>"CREATE 0040_model"},
|
221
|
+
{:title=>"DROP 0040_model"},
|
222
|
+
{:title=>"__ down"},
|
223
|
+
{:title=>"__ down"}
|
224
|
+
]
|
225
|
+
end # === it
|
226
|
+
|
227
|
+
end # === describe '__-...sql files'
|
196
228
|
|
@@ -1,7 +1,3 @@
|
|
1
|
-
-- DOWN
|
2
|
-
|
3
|
-
INSERT INTO "0030_model" (title)
|
4
|
-
VALUES ('DROP 0030_model');
|
5
1
|
|
6
2
|
-- UP:
|
7
3
|
CREATE TABLE "0030_model" (
|
@@ -10,5 +6,11 @@ CREATE TABLE "0030_model" (
|
|
10
6
|
);
|
11
7
|
|
12
8
|
|
9
|
+
-- DOWN
|
10
|
+
|
11
|
+
INSERT INTO "0030_model" (title)
|
12
|
+
VALUES ('DROP 0030_model');
|
13
|
+
|
14
|
+
|
13
15
|
|
14
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duck_duck_duck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- da99
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -145,6 +145,8 @@ files:
|
|
145
145
|
- specs/lib/models/0030_model/migrates/0010-table.sql
|
146
146
|
- specs/lib/models/0030_model/migrates/0020-insert_1.sql
|
147
147
|
- specs/lib/models/0030_model/migrates/0030-insert_2.sql
|
148
|
+
- specs/lib/models/0040_model/migrates/0010-table.sql
|
149
|
+
- specs/lib/models/0040_model/migrates/__-insert-1.sql
|
148
150
|
homepage: https://github.com/da99/duck_duck_duck
|
149
151
|
licenses:
|
150
152
|
- MIT
|