feat(14-01): add PGlite test helper and generate initial PostgreSQL migration
- Rewrite tests/helpers/db.ts to use drizzle-orm/pglite with async createTestDb() - Generate initial migration with 13 CREATE TABLE statements in drizzle-pg/ - Add drizzle-pg to biome ignore list (generated files) - PGlite smoke test confirms migrations apply and seed works
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
import { Database } from "bun:sqlite";
|
||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
||||
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");
|
||||
export async function createTestDb() {
|
||||
const db = drizzle({ schema });
|
||||
|
||||
const db = drizzle(sqlite, { schema });
|
||||
|
||||
// Apply all migrations to create tables
|
||||
migrate(db, { migrationsFolder: "./drizzle" });
|
||||
// Apply migrations from the new PostgreSQL migration directory
|
||||
await migrate(db, { migrationsFolder: "./drizzle-pg" });
|
||||
|
||||
// Seed default Uncategorized category
|
||||
db.insert(schema.categories)
|
||||
.values({ name: "Uncategorized", icon: "package" })
|
||||
.run();
|
||||
await db
|
||||
.insert(schema.categories)
|
||||
.values({ name: "Uncategorized", icon: "package" });
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user