Sha256: f1cc7e305b4b25a2a1793bb5eb4aa0ab54e29200d31f8f162db0f93f7371fb89

Contents?: true

Size: 1.6 KB

Versions: 44

Compression:

Stored size: 1.6 KB

Contents

require "rake/tasklib"

=begin

require 'pact_broker/tasks'

PactBroker::DB::MigrationTask.new do | task |
  require 'my_app/db'
  task.database_connection = MyApp::DB
end

=end

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

      attr_accessor :database_connection
      attr_accessor :options

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

      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]
                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
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.111.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.109.1 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.109.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.108.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.107.1 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.107.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.106.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.105.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.104.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.103.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.102.2 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.102.1 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.102.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.101.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.100.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.99.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.98.0 lib/pact_broker/tasks/migration_task.rb
pact_broker-2.97.0 lib/pact_broker/tasks/migration_task.rb