mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-05 13:20:57 +00:00
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
/**
|
|
* Database Health Check Endpoint
|
|
*
|
|
* Returns detailed information about the database schema state,
|
|
* including migration status, table existence, and connection info.
|
|
*
|
|
* GET /api/health/database
|
|
*
|
|
* Response:
|
|
* {
|
|
* healthy: boolean,
|
|
* database: 'sqlite' | 'postgresql',
|
|
* connection: string,
|
|
* migrationsTable: boolean,
|
|
* appliedMigrations: number,
|
|
* pendingMigrations: number,
|
|
* schemaVersion: string | null,
|
|
* tables: {
|
|
* expected: number,
|
|
* found: number,
|
|
* missing: string[]
|
|
* },
|
|
* timestamp: string
|
|
* }
|
|
*/
|
|
|
|
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { checkSchemaHealth } from '$lib/server/db/drizzle';
|
|
|
|
export const GET: RequestHandler = async () => {
|
|
try {
|
|
const health = await checkSchemaHealth();
|
|
|
|
return json(health, {
|
|
status: health.healthy ? 200 : 503,
|
|
headers: {
|
|
'Cache-Control': 'no-cache, no-store, must-revalidate'
|
|
}
|
|
});
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
|
|
return json(
|
|
{
|
|
healthy: false,
|
|
error: message,
|
|
timestamp: new Date().toISOString()
|
|
},
|
|
{
|
|
status: 500,
|
|
headers: {
|
|
'Cache-Control': 'no-cache, no-store, must-revalidate'
|
|
}
|
|
}
|
|
);
|
|
}
|
|
};
|