-
-
Save hoanghiep90/a233ccfdf4a9770cad5cdf4bdb17105d to your computer and use it in GitHub Desktop.
An initialiser to prevent app to bootstrap app on dev env if pending migrations - cover Rails 3 or newer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Place in config/initializers/00_pending_migrations.rb | |
# Raise an error and abort the run there are any pending migrations: | |
if Rails.env.development? | |
# Rails 4 way ;) | |
if Rails.version >= '4' | |
ActiveRecord::Migration.check_pending! | |
else | |
# Rails 3 way - TODO: remove when we up to Rails 4 | |
migrator = ActiveRecord::Migrator.new( | |
:up, ActiveRecord::Migrator.migrations_paths | |
) | |
if (pending = migrator.pending_migrations).any? | |
warning = <<-EOF | |
Attention! The following migrations are PENDING: | |
#{pending.map(&:filename).join("\n")} | |
Please run 'rake db:migrate'... | |
EOF | |
raise warning | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment