Skip to content

Commit

Permalink
Add migration_command accessor for overriding (#242)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-undefined committed Jul 11, 2020
1 parent 7d233fa commit d8c547a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/capistrano/tasks/migrations.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit d8c547a

Please sign in to comment.