feat(14-01): rewrite database foundation from SQLite to PostgreSQL
- Replace all 13 sqliteTable definitions with pgTable (pg-core) - Convert integer timestamps to native timestamp type with defaultNow() - Convert real columns to doublePrecision, integer used to boolean - Rewrite db connection to use postgres.js driver with DATABASE_URL - Rewrite migrate.ts to use postgres-js migrator targeting drizzle-pg/ - Convert seed.ts to async - Update drizzle.config.ts to postgresql dialect - Install postgres and @electric-sql/pglite, remove better-sqlite3
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { Database } from "bun:sqlite";
|
||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import * as schema from "./schema.ts";
|
||||
|
||||
const sqlite = new Database(process.env.DATABASE_PATH || "gearbox.db");
|
||||
sqlite.run("PRAGMA journal_mode = WAL");
|
||||
sqlite.run("PRAGMA foreign_keys = ON");
|
||||
|
||||
export const db = drizzle(sqlite, { schema });
|
||||
const connectionString =
|
||||
process.env.DATABASE_URL ||
|
||||
"postgresql://gearbox:gearbox@localhost:5432/gearbox";
|
||||
const queryClient = postgres(connectionString);
|
||||
export const db = drizzle(queryClient, { schema });
|
||||
|
||||
Reference in New Issue
Block a user