migrar en sitio

This commit is contained in:
Cat /dev/Nulo 2023-12-29 19:54:30 -03:00 committed by Nulo
parent a55b5b9104
commit bc95d9c255
2 changed files with 6 additions and 2 deletions

View file

@ -1,15 +1,16 @@
import Database from "bun:sqlite";
import { join } from "node:path";
import { join, dirname } from "node:path";
import { drizzle } from "drizzle-orm/bun-sqlite";
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import * as schema from "./schema.js";
import { DB_PATH } from "./drizzle.config.js";
const url = new URL(import.meta.url);
export function migrateDb() {
const sqlite = new Database(DB_PATH);
const db = drizzle(sqlite, { schema });
migrate(db, { migrationsFolder: join(import.meta.dir, "drizzle") });
migrate(db, { migrationsFolder: join(dirname(url.pathname), "drizzle") });
sqlite.run(`
pragma journal_mode = WAL;
PRAGMA synchronous = NORMAL;

View file

@ -1,8 +1,11 @@
import Database from "bun:sqlite";
import { drizzle } from "drizzle-orm/bun-sqlite";
import * as schema from "db-datos/schema.js";
import { migrateDb } from "db-datos/migrate.js";
import { env } from "$env/dynamic/private";
migrateDb();
const sqlite = new Database(env.DB_PATH ?? "../scraper/sqlite.db");
export const db = drizzle(sqlite, { schema });