mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-06 13:21:53 +00:00
Initial commit
This commit is contained in:
58
routes/api/health/database/+server.ts
Normal file
58
routes/api/health/database/+server.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 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'
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user