Sha256: 0a348fc60f12e1f8c1b462c30796cc769e317baccc65f7f19c01d1ba23ca4ec4

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

if defined?(ActiveRecord)
  namespace :db do
    namespace :create do
      task :all => [:load_config] do
        invoke_task_if_exists :rails_env
        run_in_all_environments do |config|
          ActiveRecord::Base.establish_connection(config)
          ActiveRecord::Tasks::DatabaseTasks.create config
        end

        if includes_test_environment? && !parallel?
          invoke_task_if_exists "parallel:create"
        end
      end
    end

    namespace :drop do
      task :all => [:load_config] do
        invoke_task_if_exists :rails_env
        run_in_all_environments do |config|
          ActiveRecord::Base.establish_connection(config)
          ActiveRecord::Tasks::DatabaseTasks.drop config
        end

        if includes_test_environment? && !parallel?
          invoke_task_if_exists "parallel:drop"
        end
      end
    end

    namespace :migrate do
      task :all => [:load_config] do
        invoke_task_if_exists :rails_env
        run_in_all_environments do |config|
          ActiveRecord::Base.establish_connection(config)
          ActiveRecord::Tasks::DatabaseTasks.migrate
        end

        if includes_test_environment? && !parallel?
          invoke_task_if_exists "parallel:migrate"
        end

        Rake::Task["db:_dump"].invoke
      end
    end

    def run_in_all_environments &block
      if defined?(ActiveRecord::Tasks::DatabaseTasks)
        ActiveRecord::Tasks::DatabaseTasks.send :each_local_configuration, &block
      else
        configs_for_environment.each &block
      end
    end

    def includes_test_environment?
      %w(development test).include?(ENV["RAILS_ENV"])
    end

    def parallel?
      !!ENV["TEST_ENV_NUMBER"]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bard-rake-0.16.0 lib/bard/rake/db_multiple_environment_sanity.rb