From d8c547a8fe93b7a7653dc636e7cfae9e45262fc0 Mon Sep 17 00:00:00 2001 From: Joe <191664+the-undefined@users.noreply.github.com> Date: Sat, 11 Jul 2020 04:35:52 +0100 Subject: [PATCH] Add migration_command accessor for overriding (#242) With rails 6 multiple database support the `db:migrate` command isn't always what is needed when deploying to an environment. Other usecases are only running migrations for one of the databases using something like `db:migrate:primary`. Exposing the accessor `migration_command` allows flexibility for more scenarios. --- CHANGELOG.md | 1 + README.md | 3 +++ lib/capistrano/tasks/migrations.rake | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 923f29a..b2c48fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # [master][] * Your contribution here! +* Added option `:migration_command` to allow overriding the default `db:migrate` used. # [1.5.0][] (May 15 2020) diff --git a/README.md b/README.md index 5bcd495..07fcf06 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,9 @@ set :migration_role, :db # Defaults to the primary :db server set :migration_servers, -> { primary(fetch(:migration_role)) } +# Defaults to `db:migrate` +set :migration_command, 'db:migrate' + # Defaults to false # Skip migration if files in db/migrate were not modified set :conditionally_migrate, true diff --git a/lib/capistrano/tasks/migrations.rake b/lib/capistrano/tasks/migrations.rake index 23cc048..f8e5a6e 100644 --- a/lib/capistrano/tasks/migrations.rake +++ b/lib/capistrano/tasks/migrations.rake @@ -22,7 +22,7 @@ namespace :deploy do on fetch(:migration_servers) do within release_path do with rails_env: fetch(:rails_env) do - execute :rake, 'db:migrate' + execute :rake, fetch(:migration_command) end end end @@ -36,5 +36,6 @@ namespace :load do set :conditionally_migrate, fetch(:conditionally_migrate, false) set :migration_role, fetch(:migration_role, :db) set :migration_servers, -> { primary(fetch(:migration_role)) } + set :migration_command, -> { fetch(:migration_command, 'db:migrate') } end end