|
3 | 3 |
|
4 | 4 | require_once __DIR__ . '/src/csrf.php'; |
5 | 5 | require_once __DIR__ . '/src/assets.php'; |
| 6 | +require_once __DIR__ . '/src/migrate.php'; |
6 | 7 |
|
7 | 8 | // Anyone reaching this page must already be signed in; require_login sends |
8 | 9 | // them to the sign-in form otherwise. |
9 | 10 | $me = require_login(); |
10 | 11 |
|
| 12 | +// Apply any migration that has not run yet. |
| 13 | +// |
| 14 | +// They used to run only from install.php, which refuses once an account |
| 15 | +// exists, or from a button on the content page that nobody has a reason to |
| 16 | +// press. So a deploy could add a column and nothing would ever create it: the |
| 17 | +// code shipped, the database did not, and the first sign was a feature failing |
| 18 | +// with a SQL error. That happened -- the vehicle photograph column was added |
| 19 | +// and never existed. |
| 20 | +// |
| 21 | +// migrate() records what it has applied and skips those, so the cost here is |
| 22 | +// one small SELECT per dashboard load. A failure is reported rather than |
| 23 | +// thrown: a migration that cannot run is worth knowing about, and it is not a |
| 24 | +// reason to refuse to show a panel that otherwise works. |
| 25 | +$migrationError = null; |
| 26 | +try { |
| 27 | + migrate(); |
| 28 | +} catch (Throwable $e) { |
| 29 | + error_log('migrate on dashboard load failed: ' . $e->getMessage()); |
| 30 | + $migrationError = $e->getMessage(); |
| 31 | +} |
| 32 | + |
11 | 33 | header('X-Frame-Options: DENY'); |
12 | 34 | header('X-Content-Type-Options: nosniff'); |
13 | 35 | header('Referrer-Policy: same-origin'); |
|
26 | 48 | <link rel="stylesheet" href="<?= asset('admin.css') ?>" /> |
27 | 49 | </head> |
28 | 50 | <body> |
| 51 | +<?php if ($migrationError !== null): ?> |
| 52 | + <div class="migration-warning"> |
| 53 | + <strong>The database is not fully up to date.</strong> |
| 54 | + Some newer features may fail until this is resolved. |
| 55 | + <span><?= e($migrationError) ?></span> |
| 56 | + </div> |
| 57 | +<?php endif; ?> |
29 | 58 |
|
30 | 59 | <!-- ===== Dashboard ===== --> |
31 | 60 | <div class="dashboard" id="dashboard"> |
|
0 commit comments