feat(01-01): configure Drizzle schema with entries table

- Schema with unified entries table (task/thought types)
- Fields: id, title, content, type, status, pinned, dueDate, timestamps
- Database connection with WAL mode
- Drizzle kit scripts (db:generate, db:migrate, db:push, db:studio)
- Database file at ./data/taskplaner.db
This commit is contained in:
Thomas Richter
2026-01-29 04:34:14 +01:00
parent 3a2e0f2e01
commit 63c5e4bddc
5 changed files with 62 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
import Database from 'better-sqlite3';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import * as schema from './schema';
import { existsSync, mkdirSync } from 'fs';
import { dirname } from 'path';
const DB_PATH = process.env.DATABASE_PATH || './data/taskplaner.db';
// Ensure data directory exists
const dbDir = dirname(DB_PATH);
if (!existsSync(dbDir)) {
mkdirSync(dbDir, { recursive: true });
}
const sqlite = new Database(DB_PATH);
// Enable WAL mode for better concurrent read performance
sqlite.pragma('journal_mode = WAL');
export const db = drizzle(sqlite, { schema });
export { schema };

View File

@@ -0,0 +1,22 @@
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
// Entry types: 'task' (actionable) or 'thought' (reference)
export const entries = sqliteTable('entries', {
id: text('id').primaryKey(), // nanoid
title: text('title'),
content: text('content').notNull(),
type: text('type', { enum: ['task', 'thought'] }).notNull().default('thought'),
status: text('status', { enum: ['open', 'done', 'archived'] }).default('open'), // for tasks
pinned: integer('pinned', { mode: 'boolean' }).default(false),
dueDate: text('due_date'), // ISO date string, nullable
createdAt: text('created_at')
.notNull()
.$defaultFn(() => new Date().toISOString()),
updatedAt: text('updated_at')
.notNull()
.$defaultFn(() => new Date().toISOString())
});
// Type inference for TypeScript
export type Entry = typeof entries.$inferSelect;
export type NewEntry = typeof entries.$inferInsert;