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;`);
|
2024-04-04 13:50:34 +00:00
|
|
|
db.run(sql`PRAGMA busy_timeout = 15000;`);
|
|
|
|
db.run(sql`PRAGMA cache_size = 1000000000;`);
|
|
|
|
// db.run(sql`PRAGMA foreign_keys = true;`);
|
|
|
|
db.run(sql`PRAGMA temp_store = memory;`);
|
2023-12-26 03:03:28 +00:00
|
|
|
}
|