2024-01-14 01:07:23 +00:00
|
|
|
// @ts-check
|
|
|
|
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
2023-12-23 23:29:55 +00:00
|
|
|
import * as schema from "./schema.js";
|
2024-01-24 23:13:20 +00:00
|
|
|
import { sql } from "drizzle-orm";
|
2024-01-29 15:47:09 +00:00
|
|
|
import { existsSync } from "node:fs";
|
|
|
|
import { join } from "node:path";
|
2023-12-23 23:29:55 +00:00
|
|
|
|
2024-01-24 23:13:20 +00:00
|
|
|
/**
|
|
|
|
* @param {import("drizzle-orm/better-sqlite3").BetterSQLite3Database<schema>} db
|
|
|
|
*/
|
|
|
|
export function migrateDb(db) {
|
2024-01-29 15:47:09 +00:00
|
|
|
let path = "drizzle/";
|
|
|
|
if (!existsSync(join(path, "meta/_journal.json")))
|
|
|
|
path = "node_modules/db-datos/drizzle";
|
|
|
|
migrate(db, { migrationsFolder: path });
|
2024-01-24 23:13:20 +00:00
|
|
|
db.run(sql`pragma journal_mode = WAL;`);
|
|
|
|
db.run(sql`PRAGMA synchronous = NORMAL;`);
|
2023-12-26 03:03:28 +00:00
|
|
|
}
|