preciazo/db-datos/migrate.ts

21 lines
598 B
TypeScript
Raw Normal View History

2023-12-24 21:12:06 +00:00
import Database from "bun:sqlite";
2023-12-29 22:54:30 +00:00
import { join, dirname } 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-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") });
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();
}