pliny 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny/db_support.rb +9 -6
- data/lib/pliny/version.rb +1 -1
- data/spec/db_support_spec.rb +16 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6f83c7b5d986610339642f0aa5ea69471dbc80
|
4
|
+
data.tar.gz: 961db5cf37d94f149b0b1fce4fe4f05f0a715f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47578679bc614de3f1b6e99a22a53bd5cb5468d84c41b822c7c7036f60fac8cc5d8aa5b83109282f037b1cce1685359a751d6a17df17501c1a40a0ae7ff25107
|
7
|
+
data.tar.gz: f2a0a12c64767f6c82d9a1430780238b882099407177f96f024d7972d6cac76f13e0cb9ed501b93c1ee46502c0aaa37683575cec8629813749dac01420fad68c
|
data/lib/pliny/db_support.rb
CHANGED
@@ -25,16 +25,19 @@ module Pliny
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def migrate
|
29
|
-
Sequel::Migrator.apply(db, "./db/migrate")
|
28
|
+
def migrate(target=nil)
|
29
|
+
Sequel::Migrator.apply(db, "./db/migrate", target)
|
30
30
|
end
|
31
31
|
|
32
32
|
def rollback
|
33
|
+
return unless db.tables.include?(:schema_migrations)
|
34
|
+
return unless current = db[:schema_migrations].order(Sequel.desc(:filename)).first
|
35
|
+
|
33
36
|
migrations = Dir["./db/migrate/*.rb"].map { |f| File.basename(f).to_i }.sort
|
34
|
-
|
35
|
-
|
36
|
-
if
|
37
|
-
target = migrations[
|
37
|
+
target = 0 # by default, rollback everything
|
38
|
+
index = migrations.index(current[:filename].to_i)
|
39
|
+
if index > 0
|
40
|
+
target = migrations[index - 1]
|
38
41
|
end
|
39
42
|
Sequel::Migrator.apply(db, "./db/migrate", target)
|
40
43
|
end
|
data/lib/pliny/version.rb
CHANGED
data/spec/db_support_spec.rb
CHANGED
@@ -40,26 +40,33 @@ describe Pliny::DbSupport do
|
|
40
40
|
|
41
41
|
describe "#rollback" do
|
42
42
|
before do
|
43
|
-
t = Time.now
|
44
|
-
File.open("#{@path}/db/migrate/#{(t-
|
43
|
+
@t = Time.now
|
44
|
+
File.open("#{@path}/db/migrate/#{(@t-2).to_i}_first.rb", "w") do |f|
|
45
45
|
f.puts "Sequel.migration { change { create_table(:first) } }"
|
46
46
|
end
|
47
47
|
|
48
|
-
File.open("#{@path}/db/migrate/#{(t-
|
48
|
+
File.open("#{@path}/db/migrate/#{(@t-1).to_i}_second.rb", "w") do |f|
|
49
49
|
f.puts "Sequel.migration { change { create_table(:second) } }"
|
50
50
|
end
|
51
|
-
|
52
|
-
File.open("#{@path}/db/migrate/#{(t-1).to_i}_third.rb", "w") do |f|
|
53
|
-
f.puts "Sequel.migration { change { create_table(:third) } }"
|
54
|
-
end
|
55
51
|
end
|
56
52
|
|
57
|
-
it "reverts
|
53
|
+
it "reverts migrations" do
|
58
54
|
support.migrate
|
59
|
-
support.rollback
|
60
55
|
assert_equal [:first, :schema_migrations, :second], DB.tables.sort
|
61
56
|
support.rollback
|
62
57
|
assert_equal [:first, :schema_migrations], DB.tables.sort
|
58
|
+
support.rollback
|
59
|
+
assert_equal [:schema_migrations], DB.tables.sort
|
60
|
+
end
|
61
|
+
|
62
|
+
it "handle blank databases (no schema_migrations table)" do
|
63
|
+
support.rollback # noop
|
64
|
+
end
|
65
|
+
|
66
|
+
it "handles databases not migrated (schema_migrations is empty)" do
|
67
|
+
support.migrate (@t-2).to_i
|
68
|
+
support.rollback # destroy table, leave schema_migrations
|
69
|
+
support.rollback # should noop
|
63
70
|
end
|
64
71
|
end
|
65
72
|
end
|