arreglar migracion cli

This commit is contained in:
Cat /dev/Nulo 2024-01-29 12:47:09 -03:00
parent cc0af3011a
commit 4669e6087f
3 changed files with 10 additions and 2 deletions

3
db-datos/migrate-cli.js Normal file
View file

@ -0,0 +1,3 @@
import { getDb } from "./db.js";
getDb();

View file

@ -2,12 +2,17 @@
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import * as schema from "./schema.js";
import { sql } from "drizzle-orm";
import { existsSync } from "node:fs";
import { join } from "node:path";
/**
* @param {import("drizzle-orm/better-sqlite3").BetterSQLite3Database<schema>} db
*/
export function migrateDb(db) {
migrate(db, { migrationsFolder: "node_modules/db-datos/drizzle" });
let path = "drizzle/";
if (!existsSync(join(path, "meta/_journal.json")))
path = "node_modules/db-datos/drizzle";
migrate(db, { migrationsFolder: path });
db.run(sql`pragma journal_mode = WAL;`);
db.run(sql`PRAGMA synchronous = NORMAL;`);
}

View file

@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"generate": "drizzle-kit generate:sqlite",
"migrate": "node db.js"
"migrate": "node migrate-cli.js"
},
"keywords": [],
"author": "",