2023-12-24 21:12:06 +00:00
|
|
|
import Database from "bun:sqlite";
|
2023-12-26 18:22:27 +00:00
|
|
|
import { join } from "node:path";
|
2023-12-24 21:12:06 +00:00
|
|
|
import { drizzle } from "drizzle-orm/bun-sqlite";
|
|
|
|
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
2023-12-23 23:29:55 +00:00
|
|
|
import * as schema from "./schema.js";
|
2023-12-26 02:05:50 +00:00
|
|
|
import { DB_PATH } from "./drizzle.config.js";
|
2023-12-23 23:29:55 +00:00
|
|
|
|
2023-12-26 03:03:28 +00:00
|
|
|
export function migrateDb() {
|
|
|
|
const sqlite = new Database(DB_PATH);
|
|
|
|
const db = drizzle(sqlite, { schema });
|
2023-12-23 23:29:55 +00:00
|
|
|
|
2023-12-26 18:22:27 +00:00
|
|
|
migrate(db, { migrationsFolder: join(import.meta.dir, "drizzle") });
|
2023-12-26 17:42:55 +00:00
|
|
|
sqlite.run(`
|
|
|
|
pragma journal_mode = WAL;
|
|
|
|
PRAGMA synchronous = NORMAL;
|
|
|
|
`);
|
2023-12-23 23:29:55 +00:00
|
|
|
|
2023-12-26 03:03:28 +00:00
|
|
|
sqlite.close();
|
|
|
|
}
|