Skip to content

Commit

Permalink
feat: expose the data migrations code as a rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 28, 2020
1 parent a316b88 commit 00ee00d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact_broker/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.run_migrations database_connection, options = {}
end

def self.run_data_migrations database_connection
PactBroker::DB::MigrateData.(connection)
PactBroker::DB::MigrateData.(database_connection)
end

def self.validate_connection_config
Expand Down
1 change: 1 addition & 0 deletions lib/pact_broker/tasks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'pact_broker/tasks/migration_task'
require 'pact_broker/tasks/data_migration_task'
require 'pact_broker/tasks/version_task'
require 'pact_broker/tasks/clean_task'
38 changes: 38 additions & 0 deletions lib/pact_broker/tasks/data_migration_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'rake/tasklib'

=begin
require 'pact_broker/tasks'
PactBroker::DB::DataMigrationTask.new do | task |
require 'my_app/db'
task.database_connection = MyApp::DB
end
=end

module PactBroker
module DB
class DataMigrationTask < ::Rake::TaskLib

attr_accessor :database_connection

def initialize &block
rake_task &block
end

def rake_task &block
namespace :pact_broker do
namespace :db do
desc "Run data migrations for pact broker database"
task :migrate_data do | t, args |
require 'pact_broker/db'
instance_eval(&block)
PactBroker::DB.run_data_migrations database_connection
end
end
end
end
end
end
end
6 changes: 6 additions & 0 deletions tasks/test_db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ PactBroker::DB::MigrationTask.new do | task |
task.database_connection = DB::PACT_BROKER_DB
end

PactBroker::DB::DataMigrationTask.new do | task |
ENV['RACK_ENV'] ||= 'test'
require 'db'
task.database_connection = DB::PACT_BROKER_DB
end

PactBroker::DB::VersionTask.new do | task |
ENV['RACK_ENV'] ||= 'test'
require 'db'
Expand Down

0 comments on commit 00ee00d

Please sign in to comment.