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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 730c26a37602ac9968f9c396bbe1132693a91c08
4
- data.tar.gz: a45ea124b26a4844a9c95aa8c0e6b6f3080a47cb
3
+ metadata.gz: fc9d363fc3f2add54ba7cc80a1f272fffd6ad9fe
4
+ data.tar.gz: becb37dc9a4644a240d85115f1bdd59d6b7ced6e
5
5
  SHA512:
6
- metadata.gz: 1da85bc4c920e2e480ec32fb08ae6bf4eaeb6b62a872a292c2ec765d37b82cd3746b4426ee8ce7a43519e019ca7eecd7e9db9c6d04f1ee73793a704b459f8d69
7
- data.tar.gz: f4eca66662ca2d2c577058b5490b74bf556b6a363686cc5742dde7f22ba5a7cbc441d7d02914412518d759d2209db948c87bfffc3c4cefae80e1aaa3db350012
6
+ metadata.gz: 8f8e635b02307254b949e69967d07b689a6c1e5c919ad24fcbce22f3ec78397652e7f9929038fbe98c3b65e3485fcc605aa49adba0c61f4ff7ba3220281c9574
7
+ data.tar.gz: b3a25e2d1cf9ec7a7544e2ec2a6f6a82343e8c22e7a5e5b3b8d843992a6349f635be4df266d0bee276afeb4f57e5528fcbafbe363448a37f77ff2fd1d5717bdb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.1.0
1
+ 4.2.0
@@ -74,11 +74,18 @@ class Duck_Duck_Duck
74
74
  fail ArgumentError, "Name required."
75
75
  end
76
76
 
77
- @files = `find . -iregex ".+/#{name}/migrates/.+\.sql"`
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 = @files.sort.reverse.map { |f|
160
- ver = file_to_ver(f)
161
- next unless ver <= rec[:version]
162
- [ ver, Duck_Duck_Duck.read_file(f)[:DOWN] ]
163
- }.compact
164
-
165
- if files.empty?
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
@@ -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
 
@@ -0,0 +1,14 @@
1
+
2
+ -- UP:
3
+ INSERT INTO "0040_model" (title)
4
+ VALUES ('CREATE 0040_model');
5
+
6
+
7
+ -- DOWN
8
+
9
+ INSERT INTO "0040_model" (title)
10
+ VALUES ('DROP 0040_model');
11
+
12
+
13
+
14
+
@@ -0,0 +1,16 @@
1
+
2
+
3
+ CREATE TABLE IF NOT EXISTS "0040_model" (
4
+ id serial NOT NULL PRIMARY KEY,
5
+ title varchar(100)
6
+ );
7
+
8
+ INSERT INTO "0040_model" (title)
9
+ VALUES ('__ up');
10
+
11
+ -- DOWN:
12
+
13
+
14
+ INSERT INTO "0040_model" (title)
15
+ VALUES ('__ down');
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.1.0
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-28 00:00:00.000000000 Z
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