stored = ActiveRecord::Migrator.last_stored_environment if ActiveRecord::Migrator.protected_environment? raise ActiveRecord::ProtectedEnvironmentError.new(stored) end if stored && stored != current raise ActiveRecord::EnvironmentMismatchError.new(current: current, stored: stored) end end rescue ActiveRecord::NoDatabaseError end