Skip to content

Commit

Permalink
feat: add Migrator#latest? method
Browse files Browse the repository at this point in the history
May be useful for Continuous Delivery (e.g. abort when not on the latest migration)

Closes #16
  • Loading branch information
vladfaust committed Jun 29, 2018
1 parent edcda22 commit 6c306ac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/migrate/migrator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ describe Migrate::Migrator do
end
end

describe "#latest?" do
context "on fresh DB" do
it "returns false" do
migrator.latest?.should eq false
end
end
end

describe "#next_version" do
context "on fresh DB" do
it "returns 1" do
Expand Down Expand Up @@ -65,6 +73,14 @@ describe Migrate::Migrator do
end
end

describe "#latest?" do
context "after migrations 1 & 2" do
it "returns false" do
migrator.latest?.should eq false
end
end
end

describe "#next_version" do
context "after migrations 1 & 2" do
it "returns 10" do
Expand Down Expand Up @@ -121,6 +137,14 @@ describe Migrate::Migrator do
end
end

describe "#latest?" do
context "on the last migration" do
it "returns true" do
migrator.latest?.should eq true
end
end
end

describe "#redo" do
it do
migrator.redo
Expand Down
5 changes: 5 additions & 0 deletions src/migrate/migrator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ module Migrate
end
end

# Return if current version is the latest one.
def latest?
next_version.nil?
end

# Apply all the migrations from current version to the last one.
def to_latest
to(all_versions.last)
Expand Down

0 comments on commit 6c306ac

Please sign in to comment.