Skip to content

Commit 143613e

Browse files
committed
feat(database): allow options to be passed to Sequel migrate via the MigrationTask
1 parent a755010 commit 143613e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/pact_broker/tasks/migration_task.rb

+20-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ module DB
1616
class MigrationTask < ::Rake::TaskLib
1717

1818
attr_accessor :database_connection
19+
attr_accessor :options
1920

2021
def initialize &block
22+
@options = {}
2123
rake_task &block
2224
end
2325

@@ -27,12 +29,29 @@ def rake_task &block
2729
desc "Run sequel migrations for pact broker database"
2830
task :migrate, [:target] do | t, args |
2931
require 'pact_broker/db/migrate'
32+
require 'pact_broker/db/version'
33+
3034
instance_eval(&block)
31-
options = {}
35+
3236
if args[:target]
3337
options[:target] = args[:target].to_i
3438
end
39+
40+
if (logger = database_connection.loggers.first)
41+
current_version = PactBroker::DB::Version.call(database_connection)
42+
if options[:target]
43+
logger.info "Migrating from schema version #{current_version} to #{options[:target]}"
44+
else
45+
logger.info "Migrating from schema version #{current_version} to latest"
46+
end
47+
end
48+
3549
PactBroker::DB::Migrate.call(database_connection, options)
50+
51+
if logger
52+
current_version = PactBroker::DB::Version.call(database_connection)
53+
logger.info "Current schema version is now #{current_version}"
54+
end
3655
end
3756
end
3857
end

0 commit comments

Comments
 (0)