Class: PactBroker::DB::MigrationTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- PactBroker::DB::MigrationTask
- Defined in:
- lib/pact_broker/tasks/migration_task.rb
Instance Attribute Summary collapse
-
#database_connection ⇒ Object
Returns the value of attribute database_connection.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(&block) ⇒ MigrationTask
constructor
A new instance of MigrationTask.
- #rake_task(&block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ MigrationTask
Returns a new instance of MigrationTask.
21 22 23 24 |
# File 'lib/pact_broker/tasks/migration_task.rb', line 21 def initialize &block @options = {} rake_task &block end |
Instance Attribute Details
#database_connection ⇒ Object
Returns the value of attribute database_connection.
18 19 20 |
# File 'lib/pact_broker/tasks/migration_task.rb', line 18 def database_connection @database_connection end |
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/pact_broker/tasks/migration_task.rb', line 19 def @options end |
Instance Method Details
#rake_task(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pact_broker/tasks/migration_task.rb', line 26 def rake_task &block namespace :pact_broker do namespace :db do 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) if args[:target] [:target] = args[:target].to_i end if (logger = database_connection.loggers.first) current_version = PactBroker::DB::Version.call(database_connection) if [:target] logger.info "Migrating from schema version #{current_version} to #{[:target]}" else logger.info "Migrating from schema version #{current_version} to latest" end end PactBroker::DB::Migrate.call(database_connection, ) if logger current_version = PactBroker::DB::Version.call(database_connection) logger.info "Current schema version is now #{current_version}" end end end end end |