diff --git a/.gitignore b/.gitignore index 603d0b0..7a12b10 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,10 @@ Thumbs.db vite.config.js.timestamp-* vite.config.ts.timestamp-* -# Database -/data/ +# Data directory (persistent data) +data/*.db +data/*.db-wal +data/*.db-shm +data/attachments/* +!data/.gitkeep +!data/attachments/.gitkeep diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/attachments/.gitkeep b/data/attachments/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/hooks.server.ts b/src/hooks.server.ts new file mode 100644 index 0000000..c3165ed --- /dev/null +++ b/src/hooks.server.ts @@ -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); +}; diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts new file mode 100644 index 0000000..a24d39e --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,24 @@ +import type { PageServerLoad } from './$types'; +import { entryRepository } from '$lib/server/db/repository'; + +export const load: PageServerLoad = async () => { + const count = entryRepository.count(); + + // Create a test entry if none exist (for verification) + let testEntry = null; + if (count === 0) { + testEntry = entryRepository.create({ + title: 'Foundation Test', + content: 'This entry was created to verify the foundation is working.', + type: 'thought' + }); + } + + const entries = entryRepository.getAll({ limit: 5 }); + + return { + dbStatus: 'connected', + entryCount: testEntry ? count + 1 : count, + recentEntries: entries + }; +}; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index b14d9b5..87d05bd 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,2 +1,46 @@ -

TaskPlanner

-

Foundation setup complete.

+ + +
+
+

TaskPlanner

+

Foundation Phase Complete

+ +
+

System Status

+ +
+
+ + Database: {data.dbStatus} +
+
+ + Entries in database: {data.entryCount} +
+
+ + Repository layer: operational +
+
+
+ + {#if data.recentEntries.length > 0} +
+

Recent Entries

+
    + {#each data.recentEntries as entry} +
  • +
    {entry.title || '(no title)'}
    +
    {entry.content}
    +
    + Type: {entry.type} | Created: {new Date(entry.createdAt).toLocaleString()} +
    +
  • + {/each} +
+
+ {/if} +
+