mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-26 11:36:20 +00:00
migrar en sitio
This commit is contained in:
parent
d45e505470
commit
cf8ef7a4fb
2 changed files with 6 additions and 2 deletions
|
@ -1,15 +1,16 @@
|
||||||
import Database from "bun:sqlite";
|
import Database from "bun:sqlite";
|
||||||
import { join } from "node:path";
|
import { join, dirname } from "node:path";
|
||||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||||
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
||||||
import * as schema from "./schema.js";
|
import * as schema from "./schema.js";
|
||||||
import { DB_PATH } from "./drizzle.config.js";
|
import { DB_PATH } from "./drizzle.config.js";
|
||||||
|
|
||||||
|
const url = new URL(import.meta.url);
|
||||||
export function migrateDb() {
|
export function migrateDb() {
|
||||||
const sqlite = new Database(DB_PATH);
|
const sqlite = new Database(DB_PATH);
|
||||||
const db = drizzle(sqlite, { schema });
|
const db = drizzle(sqlite, { schema });
|
||||||
|
|
||||||
migrate(db, { migrationsFolder: join(import.meta.dir, "drizzle") });
|
migrate(db, { migrationsFolder: join(dirname(url.pathname), "drizzle") });
|
||||||
sqlite.run(`
|
sqlite.run(`
|
||||||
pragma journal_mode = WAL;
|
pragma journal_mode = WAL;
|
||||||
PRAGMA synchronous = NORMAL;
|
PRAGMA synchronous = NORMAL;
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import Database from "bun:sqlite";
|
import Database from "bun:sqlite";
|
||||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||||
import * as schema from "db-datos/schema.js";
|
import * as schema from "db-datos/schema.js";
|
||||||
|
import { migrateDb } from "db-datos/migrate.js";
|
||||||
import { env } from "$env/dynamic/private";
|
import { env } from "$env/dynamic/private";
|
||||||
|
|
||||||
|
migrateDb();
|
||||||
|
|
||||||
const sqlite = new Database(env.DB_PATH ?? "../scraper/sqlite.db");
|
const sqlite = new Database(env.DB_PATH ?? "../scraper/sqlite.db");
|
||||||
|
|
||||||
export const db = drizzle(sqlite, { schema });
|
export const db = drizzle(sqlite, { schema });
|
||||||
|
|
Loading…
Reference in a new issue