-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #17
- Loading branch information
Showing
7 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "../spec_helper" | ||
|
||
db = DB.open(ENV["DATABASE_URL"]) | ||
|
||
{% for table in %w(foo bar baz) %} | ||
def {{table.id}}_exists?(db) | ||
db.scalar("SELECT COUNT(*) FROM {{table.id}}").as(Int64) | ||
rescue | ||
false | ||
end | ||
{% end %} | ||
|
||
describe "Migrate::Migrator with errors" do | ||
drop_db | ||
|
||
migrator = Migrate::Migrator.new( | ||
db, | ||
nil, | ||
File.join("spec", "migrations_with_errors") | ||
) | ||
|
||
describe "direction-specific errors" do | ||
it do | ||
migrator.up | ||
|
||
expect_raises Migrate::Migration::Error do | ||
migrator.down | ||
end | ||
|
||
migrator.current_version.should eq 1 | ||
end | ||
end | ||
|
||
describe "top-level errors" do | ||
it do | ||
expect_raises Migrate::Migration::Error do | ||
migrator.up | ||
end | ||
|
||
migrator.current_version.should eq 1 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- +migrate up | ||
CREATE TABLE foo ( | ||
id SERIAL PRIMARY KEY, | ||
content TEXT NOT NULL | ||
); | ||
|
||
-- Indexes | ||
CREATE UNIQUE INDEX foo_content_index ON foo (content); | ||
|
||
-- +migrate down | ||
-- +migrate error Could not migrate down from version 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- +migrate error Nope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Migrate | ||
struct Migration | ||
# Could be raised after `error` command. See README for examples. | ||
class Error < Exception | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters