Outrigger allows you to tag your migrations so that you can have complete control. This is especially useful for zero downtime deploys to Production environments.
Starting with version 1.2.3
, this gem requires RuboCop version 0.52.0 or higher, because of
a backwards-incompatible change to how cops report offenses.
gem "rubocop", "~> 0.52.0"
- Add
gem outrigger
to your Gemfile and runbundle install
- Tag migrations like so.
class PreDeployMigration < ActiveRecord::Migration
tag :predeploy
end
class PostDeployMigration < ActiveRecord::Migration
tag :super_fun
end
- Run only the migrations you want.
rake db:migrate:tagged[predeploy]
orrake db:migrate:tagged[super_fun]
Using with Switchman
If your application is also using Switchman to manage multiple shards, you'll
want the rake db:migrate:tagged
task to run against all shards, not
just the default shard. To do this, add to a rake task file such as
lib/tasks/myapp.rake
:
Switchman::Rake.shardify_task('db:migrate:tagged')
Passing multiple tags to db:migrate:tagged
means only run migrations that have
all of the given tags.
rake db:migrate:tagged[predeploy, dynamodb]
means run only migrations
tagged with both predeploy
and dynamodb
. It will not run migrations tagged
just predeploy
.
Outrigger comes with a custom RuboCop linter that you can add to your project, to verify that all migrations have at least one valid tag.
Put this into your .rubocop.yml
.
require:
- outrigger/cops/migration/tagged
Migration/Tagged:
Enabled: true
AllowedTags:
- predeploy
- postdeploy
Modify AllowedTags
as necessary. Note that due to a bug in RuboCop, you'll
currently get a warning on each run:
Warning: unrecognized cop Migration/Tagged found in .rubocop.yml
This is unfortunate, but can be safely ignored.