Files
paperclip/packages/db/src/migrate.ts
Forgotten 4bc8e8baa9 Add embedded PGlite support as zero-config database option
Add @electric-sql/pglite so the server can run without an external
Postgres instance. When DATABASE_URL is not set, the server auto-creates
an embedded PGlite database in ./data/pglite with schema push on startup.

- Add createPgliteDb() alongside the existing createDb()
- Make DATABASE_URL optional in server config
- Update drizzle config to glob schema files
- Update migrate script to support both Postgres and PGlite
- Add data/ to .gitignore for local PGlite storage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 19:07:37 -06:00

24 lines
820 B
TypeScript

import { migrate as migratePg } from "drizzle-orm/postgres-js/migrator";
import { migrate as migratePglite } from "drizzle-orm/pglite/migrator";
import postgres from "postgres";
import { PGlite } from "@electric-sql/pglite";
import { drizzle as drizzlePg } from "drizzle-orm/postgres-js";
import { drizzle as drizzlePglite } from "drizzle-orm/pglite";
const migrationsFolder = new URL("./migrations", import.meta.url).pathname;
const url = process.env.DATABASE_URL;
if (url) {
const sql = postgres(url, { max: 1 });
const db = drizzlePg(sql);
await migratePg(db, { migrationsFolder });
await sql.end();
} else {
const client = new PGlite("./data/pglite");
const db = drizzlePglite({ client });
await migratePglite(db, { migrationsFolder });
await client.close();
}
console.log("Migrations complete");