From cf8ef7a4fb51167047e9d32ab9050ba628cf21a0 Mon Sep 17 00:00:00 2001 From: Nulo Date: Fri, 29 Dec 2023 19:54:30 -0300 Subject: [PATCH] migrar en sitio --- db-datos/migrate.ts | 5 +++-- sitio/src/lib/server/db.ts | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/db-datos/migrate.ts b/db-datos/migrate.ts index cb47034..c45fb9b 100644 --- a/db-datos/migrate.ts +++ b/db-datos/migrate.ts @@ -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; diff --git a/sitio/src/lib/server/db.ts b/sitio/src/lib/server/db.ts index 7462d9c..a2722b3 100644 --- a/sitio/src/lib/server/db.ts +++ b/sitio/src/lib/server/db.ts @@ -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 });