Skip to content

Commit c8a733d

Browse files
committed
Also generate migration errors in production
1 parent 8d9ff07 commit c8a733d

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

app/middleware/pending_migration_catcher.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ def initialize(app)
77

88
def call(env)
99
@app.call(env)
10-
rescue ActiveRecord::PendingMigrationError, ActiveRecord::NoDatabaseError => e
11-
render_maintenance_page(e)
10+
rescue ActiveRecord::PendingMigrationError, ActiveRecord::NoDatabaseError
11+
render_maintenance_page
1212
end
1313

1414
private
1515

16-
def render_maintenance_page(_error)
16+
def render_maintenance_page
1717
html = <<~HTML
1818
<!DOCTYPE html>
1919
<html>

config/environments/production.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
# Do not dump schema after migrations.
9393
config.active_record.dump_schema_after_migration = false
9494

95+
# Raise PendingMigrationError on page load when migrations are pending.
96+
config.active_record.migration_error = :page_load
97+
9598
# Only use :id for inspections in production.
9699
config.active_record.attributes_for_inspect = [ :id ]
97100

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
if Rails.env.development?
1010
get "preview/maintenance" => ->(env) {
11-
PendingMigrationCatcher.new(nil).send(:render_maintenance_page, nil)
11+
PendingMigrationCatcher.new(nil).send(:render_maintenance_page)
1212
}
1313
end
1414
get "messages/by-id/*message_id", to: "messages#by_message_id", as: :message_by_id, format: false

0 commit comments

Comments
 (0)