Last active
November 8, 2016 09:03
-
-
Save runlevel5/b4569945d6d525d900af7489e095b5e9 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