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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc0fc3ea6bd2bf5b8c5b6acdcf1cabf32ea781d5
4
- data.tar.gz: 68bcfd4977381a765954e04884680dfaefdb5b4e
3
+ metadata.gz: eb6f83c7b5d986610339642f0aa5ea69471dbc80
4
+ data.tar.gz: 961db5cf37d94f149b0b1fce4fe4f05f0a715f84
5
5
  SHA512:
6
- metadata.gz: 9a7c5e06960e5076cf66d5f3951acdba7e19152d1294dbc79c6946333f701bf574b9f520d0d3fe52256a5586cf8ebdb279870785f16e6db5b66d2601d880ff0c
7
- data.tar.gz: 67a0baee927f357155076aa8466d4358abd1b0ef6d68dec6c9db69853db8b31ef042162a50b8945cad12965411dd41b697bd495ca70bb7accb3e8dcb3ce7e4e5
6
+ metadata.gz: 47578679bc614de3f1b6e99a22a53bd5cb5468d84c41b822c7c7036f60fac8cc5d8aa5b83109282f037b1cce1685359a751d6a17df17501c1a40a0ae7ff25107
7
+ data.tar.gz: f2a0a12c64767f6c82d9a1430780238b882099407177f96f024d7972d6cac76f13e0cb9ed501b93c1ee46502c0aaa37683575cec8629813749dac01420fad68c
@@ -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
- current = db[:schema_migrations].order(Sequel.desc(:filename)).first[:filename].to_i
35
- target = 0 # by default, rollback everything
36
- if i = migrations.index(current)
37
- target = migrations[i - 1] || 0
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
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -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-3).to_i}_first.rb", "w") do |f|
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-2).to_i}_second.rb", "w") do |f|
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 one migration" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pliny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur Leach