feat(01-02): add data directory, server hooks, and verification page
- Create data/ directory with attachments/ subdirectory and .gitkeep files - Update .gitignore to track .gitkeep but ignore database files - Server hooks initialize database on first request - Page server load fetches entries and creates test entry if none exist - Verification page shows database status, entry count, and recent entries
This commit is contained in:
23
src/hooks.server.ts
Normal file
23
src/hooks.server.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db';
|
||||
import { entries } from '$lib/server/db/schema';
|
||||
|
||||
// Ensure database tables exist on first request
|
||||
let initialized = false;
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
if (!initialized) {
|
||||
// Run a simple query to ensure connection works
|
||||
// Drizzle with push handles schema creation, but this verifies connectivity
|
||||
try {
|
||||
db.select().from(entries).limit(1).all();
|
||||
initialized = true;
|
||||
console.log('Database initialized successfully');
|
||||
} catch (error) {
|
||||
console.error('Database initialization failed:', error);
|
||||
// Don't block - let the error propagate to the request
|
||||
}
|
||||
}
|
||||
|
||||
return resolve(event);
|
||||
};
|
||||
Reference in New Issue
Block a user