|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class PendingMigrationCatcher |
| 4 | + def initialize(app) |
| 5 | + @app = app |
| 6 | + end |
| 7 | + |
| 8 | + def call(env) |
| 9 | + @app.call(env) |
| 10 | + rescue ActiveRecord::PendingMigrationError, ActiveRecord::NoDatabaseError => e |
| 11 | + render_maintenance_page(e) |
| 12 | + end |
| 13 | + |
| 14 | + private |
| 15 | + |
| 16 | + def render_maintenance_page(_error) |
| 17 | + html = <<~HTML |
| 18 | + <!DOCTYPE html> |
| 19 | + <html> |
| 20 | + <head> |
| 21 | + <title>Upgrade in Progress</title> |
| 22 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 23 | + <meta http-equiv="refresh" content="30"> |
| 24 | + <style> |
| 25 | + * { margin: 0; padding: 0; box-sizing: border-box; } |
| 26 | + body { |
| 27 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; |
| 28 | + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
| 29 | + min-height: 100vh; |
| 30 | + display: flex; |
| 31 | + align-items: center; |
| 32 | + justify-content: center; |
| 33 | + padding: 20px; |
| 34 | + } |
| 35 | + .container { |
| 36 | + background: white; |
| 37 | + border-radius: 16px; |
| 38 | + padding: 48px; |
| 39 | + max-width: 500px; |
| 40 | + text-align: center; |
| 41 | + box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); |
| 42 | + } |
| 43 | + .icon { |
| 44 | + font-size: 64px; |
| 45 | + margin-bottom: 24px; |
| 46 | + } |
| 47 | + h1 { |
| 48 | + color: #1a202c; |
| 49 | + font-size: 28px; |
| 50 | + margin-bottom: 16px; |
| 51 | + } |
| 52 | + p { |
| 53 | + color: #4a5568; |
| 54 | + font-size: 16px; |
| 55 | + line-height: 1.6; |
| 56 | + margin-bottom: 24px; |
| 57 | + } |
| 58 | + .spinner { |
| 59 | + width: 40px; |
| 60 | + height: 40px; |
| 61 | + border: 4px solid #e2e8f0; |
| 62 | + border-top-color: #667eea; |
| 63 | + border-radius: 50%; |
| 64 | + animation: spin 1s linear infinite; |
| 65 | + margin: 0 auto; |
| 66 | + } |
| 67 | + @keyframes spin { |
| 68 | + to { transform: rotate(360deg); } |
| 69 | + } |
| 70 | + .note { |
| 71 | + color: #718096; |
| 72 | + font-size: 14px; |
| 73 | + margin-top: 24px; |
| 74 | + } |
| 75 | + </style> |
| 76 | + </head> |
| 77 | + <body> |
| 78 | + <div class="container"> |
| 79 | + <div class="icon">🚀</div> |
| 80 | + <h1>Upgrade in Progress</h1> |
| 81 | + <p>We're currently upgrading the system to bring you new features and improvements. This should only take a moment.</p> |
| 82 | + <div class="spinner"></div> |
| 83 | + <p class="note">This page will automatically refresh.</p> |
| 84 | + </div> |
| 85 | + </body> |
| 86 | + </html> |
| 87 | + HTML |
| 88 | + |
| 89 | + [ |
| 90 | + 503, |
| 91 | + { |
| 92 | + "Content-Type" => "text/html; charset=utf-8", |
| 93 | + "Retry-After" => "30" |
| 94 | + }, |
| 95 | + [html] |
| 96 | + ] |
| 97 | + end |
| 98 | +end |
0 commit comments