From 891bb248c86d3fb65f314cecafe7a75c9cd20b2b Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 15 Mar 2026 21:30:39 +0100 Subject: [PATCH] fix: use bun-sqlite migrator instead of drizzle-kit push in Docker drizzle-kit push depends on better-sqlite3 which isn't supported in Bun, causing migrations to fail and the server to crash-loop in prod. Replace with drizzle-orm/bun-sqlite/migrator that applies the existing SQL migration files using the native bun:sqlite driver. Co-Authored-By: Claude Opus 4.6 --- entrypoint.sh | 2 +- src/db/migrate.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/db/migrate.ts diff --git a/entrypoint.sh b/entrypoint.sh index 5aec280..d0f62a0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ #!/bin/sh set -e -bun run db:push +bun run src/db/migrate.ts exec bun run src/server/index.ts diff --git a/src/db/migrate.ts b/src/db/migrate.ts new file mode 100644 index 0000000..f7bd12d --- /dev/null +++ b/src/db/migrate.ts @@ -0,0 +1,13 @@ +import { Database } from "bun:sqlite"; +import { drizzle } from "drizzle-orm/bun-sqlite"; +import { migrate } from "drizzle-orm/bun-sqlite/migrator"; + +const sqlite = new Database(process.env.DATABASE_PATH || "gearbox.db"); +sqlite.run("PRAGMA journal_mode = WAL"); +sqlite.run("PRAGMA foreign_keys = ON"); + +const db = drizzle(sqlite); +migrate(db, { migrationsFolder: "./drizzle" }); + +sqlite.close(); +console.log("Migrations applied successfully");