preciazo/db-datos/migrate.js

22 lines
624 B
JavaScript
Raw Normal View History

// @ts-check
import Database from "better-sqlite3";
2023-12-29 22:54:30 +00:00
import { join, dirname } from "node:path";
import { drizzle } from "drizzle-orm/better-sqlite3";
import { migrate } from "drizzle-orm/better-sqlite3/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-29 22:54:30 +00:00
const url = new URL(import.meta.url);
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-29 22:54:30 +00:00
migrate(db, { migrationsFolder: join(dirname(url.pathname), "drizzle") });
sqlite.exec(`
2023-12-26 17:42:55 +00:00
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();
}