Skip to content

Instantly share code, notes, and snippets.

@hoanghiep90
Forked from runlevel5/00_pending_migrations.rb
Created November 8, 2016 09:03
Show Gist options
  • Save hoanghiep90/a233ccfdf4a9770cad5cdf4bdb17105d to your computer and use it in GitHub Desktop.
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
## 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