Sha256: d214caa76c3b5212a0445384c4830b4ba8d93c615473d7bf5e93efbb09db2889

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require "ridgepole/replace_db_task/executor"

namespace :db do
  desc 'db migrate use ridgepole'
  task migrate: :environment do
    rails_env = ENV.fetch('RAILS_ENV', 'development')

    ::Ridgepole::ReplaceDbTask.config.spec_configs.each do |spec_config|
      apply(rails_env, spec_config)

      envs = spec_config.multiple_migration_settings.dig(rails_env.to_sym) || []
      envs.each do |env|
        apply(env, spec_config)
      end
    end
  end

  desc 'apply dry run'
  task apply_dry_run: :environment do
    rails_env = ENV.fetch('RAILS_ENV', 'development')

    ::Ridgepole::ReplaceDbTask.config.spec_configs.each do |spec_config|
      dry_run(rails_env, spec_config)
    end
  end

  private

  def apply(env, spec_config)
    execute_ridgepole(env, spec_config.spec_name, spec_config.other_options, false) { |line| puts line }
  end

  def dry_run(env, spec_config)
    execute_ridgepole(env, spec_config.spec_name, spec_config.other_options, true) { |line| puts line }
  end

  def execute_ridgepole(env, spec_name, other_options, dry_run, &block)
    ::Ridgepole::ReplaceDbTask::Executor.call(
      env: env,
      spec_name: spec_name,
      other_options: other_options,
      block: block,
      dry_run: dry_run
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ridgepole-replace_db_task-1.0.0 lib/tasks/replaced_db.rake