chore(18-03): apply 18-01 schema foundation as dependency baseline

This commit is contained in:
2026-04-05 13:04:09 +02:00
parent f7c9f3dc94
commit 89b0496845
20 changed files with 3022 additions and 473 deletions

View File

@@ -1,21 +1,40 @@
import { Database } from "bun:sqlite";
import { drizzle } from "drizzle-orm/bun-sqlite";
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import { PGlite } from "@electric-sql/pglite";
import { drizzle } from "drizzle-orm/pglite";
import { migrate } from "drizzle-orm/pglite/migrator";
import * as schema from "../../src/db/schema.ts";
export function createTestDb() {
const sqlite = new Database(":memory:");
sqlite.run("PRAGMA foreign_keys = ON");
type Db = ReturnType<typeof drizzle<typeof schema>>;
const db = drizzle(sqlite, { schema });
export async function createTestDb() {
const client = new PGlite();
const db = drizzle(client, { schema });
// Apply all migrations to create tables
migrate(db, { migrationsFolder: "./drizzle" });
await migrate(db, { migrationsFolder: "./drizzle-pg" });
// Seed default Uncategorized category
db.insert(schema.categories)
.values({ name: "Uncategorized", icon: "package" })
.run();
// Seed a test user
const [user] = await db
.insert(schema.users)
.values({ logtoSub: "test-user-sub" })
.returning();
return db;
// Seed per-user Uncategorized category
await db
.insert(schema.categories)
.values({ name: "Uncategorized", icon: "package", userId: user.id });
return { db, userId: user.id };
}
export async function createSecondTestUser(db: Db) {
const [user] = await db
.insert(schema.users)
.values({ logtoSub: "test-user-2-sub" })
.returning();
await db
.insert(schema.categories)
.values({ name: "Uncategorized", icon: "package", userId: user.id });
return user.id;
}