Run migrations on server startup
This commit is contained in:
@@ -181,15 +181,19 @@ router.post('/change-password', asyncRoute(async (req, res) => {
|
||||
|
||||
router.post('/diagnostics', asyncRoute(async (_req, res) => {
|
||||
const tableResult = await query<{
|
||||
current_schema: string;
|
||||
users_table: string | null;
|
||||
user_roles_table: string | null;
|
||||
sessions_table: string | null;
|
||||
migrations_table: string | null;
|
||||
}>(
|
||||
`
|
||||
SELECT
|
||||
to_regclass('public.users')::text AS users_table,
|
||||
to_regclass('public.user_roles')::text AS user_roles_table,
|
||||
to_regclass('public.user_sessions')::text AS sessions_table
|
||||
current_schema() AS current_schema,
|
||||
to_regclass('users')::text AS users_table,
|
||||
to_regclass('user_roles')::text AS user_roles_table,
|
||||
to_regclass('user_sessions')::text AS sessions_table,
|
||||
to_regclass('schema_migrations')::text AS migrations_table
|
||||
`,
|
||||
);
|
||||
const tables = tableResult.rows[0];
|
||||
@@ -202,6 +206,8 @@ router.post('/diagnostics', asyncRoute(async (_req, res) => {
|
||||
roles: string[];
|
||||
}> = [];
|
||||
let userQueryError: string | undefined;
|
||||
let migrations: string[] = [];
|
||||
let migrationQueryError: string | undefined;
|
||||
|
||||
if (tables?.users_table && tables.user_roles_table) {
|
||||
try {
|
||||
@@ -234,12 +240,25 @@ router.post('/diagnostics', asyncRoute(async (_req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (tables?.migrations_table) {
|
||||
try {
|
||||
const migrationResult = await query<{ filename: string }>(
|
||||
'SELECT filename FROM schema_migrations ORDER BY filename',
|
||||
);
|
||||
migrations = migrationResult.rows.map((row) => row.filename);
|
||||
} catch (error) {
|
||||
migrationQueryError = error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
}
|
||||
|
||||
ok(res, {
|
||||
authApi: true,
|
||||
checkedAt: new Date().toISOString(),
|
||||
tables,
|
||||
users,
|
||||
userQueryError,
|
||||
migrations,
|
||||
migrationQueryError,
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user