Skip to content

Commit

Permalink
feat: warn when no queries to run
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
vladfaust committed Oct 15, 2018
1 parent 9d56ddf commit f315a8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion spec/migrate/migrator_with_errors_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe "Migrate::Migrator with errors" do

migrator = Migrate::Migrator.new(
db,
nil,
Logger.new(STDOUT).tap(&.level = Logger::DEBUG),
File.join("spec", "migrations_with_errors")
)

Expand Down
8 changes: 0 additions & 8 deletions spec/migrations_with_errors/1.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
-- +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
10 changes: 7 additions & 3 deletions src/migrate/migrator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,13 @@ module Migrate
end

@db.transaction do |tx|
queries.not_nil!.each do |query|
@logger.try &.debug(query)
tx.connection.exec(query)
if queries.not_nil!.empty?
@logger.try &.warn("No queries to run in migration file with version #{version}, applying anyway")
else
queries.not_nil!.each do |query|
@logger.try &.debug(query)
tx.connection.exec(query)
end
end

@logger.try &.debug(update_version_query(version))
Expand Down

0 comments on commit f315a8e

Please sign in to comment.