Skip to content

Commit

Permalink
feat(database): allow options to be passed to Sequel migrate via the …
Browse files Browse the repository at this point in the history
…MigrationTask
  • Loading branch information
bethesque committed Jun 1, 2020
1 parent a755010 commit 143613e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/pact_broker/tasks/migration_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ module DB
class MigrationTask < ::Rake::TaskLib

attr_accessor :database_connection
attr_accessor :options

def initialize &block
@options = {}
rake_task &block
end

Expand All @@ -27,12 +29,29 @@ def rake_task &block
desc "Run sequel migrations for pact broker database"
task :migrate, [:target] do | t, args |
require 'pact_broker/db/migrate'
require 'pact_broker/db/version'

instance_eval(&block)
options = {}

if args[:target]
options[:target] = args[:target].to_i
end

if (logger = database_connection.loggers.first)
current_version = PactBroker::DB::Version.call(database_connection)
if options[:target]
logger.info "Migrating from schema version #{current_version} to #{options[:target]}"
else
logger.info "Migrating from schema version #{current_version} to latest"
end
end

PactBroker::DB::Migrate.call(database_connection, options)

if logger
current_version = PactBroker::DB::Version.call(database_connection)
logger.info "Current schema version is now #{current_version}"
end
end
end
end
Expand Down

0 comments on commit 143613e

Please sign in to comment.