Database init
This commit is contained in:
parent
b4c840b4f9
commit
1e5497b3c2
2 changed files with 25 additions and 4 deletions
|
|
@ -1,10 +1,33 @@
|
|||
import type { Handle } from '@sveltejs/kit';
|
||||
import { dev } from '$app/environment';
|
||||
import { db } from '$lib/db';
|
||||
import { env } from '$env/dynamic/private';
|
||||
|
||||
// Flag to ensure startup tasks only run once
|
||||
|
||||
export async function init() {
|
||||
if (!env.DATABASE_URL) return;
|
||||
|
||||
console.log('🚀 Initializing server...');
|
||||
|
||||
try {
|
||||
// Test database connection
|
||||
console.log('📊 Testing database connection...');
|
||||
await db.testConnection();
|
||||
|
||||
// Run database migrations
|
||||
console.log('🔄 Running database migrations...');
|
||||
await db.createTables();
|
||||
|
||||
console.log('✅ Server initialization complete!');
|
||||
} catch (error) {
|
||||
console.error('❌ Server initialization failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// The handle function runs on every request
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
// Initialize on first request (lazy initialization)
|
||||
|
||||
// Add custom headers or modify request/response if needed
|
||||
const response = await resolve(event);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
runKm: 0
|
||||
});
|
||||
|
||||
$inspect(form);
|
||||
|
||||
onMount(async () => {
|
||||
const result = await getTodaysWorkout();
|
||||
form = result.data ?? form;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue