arreglar migracion cli

This commit is contained in:
Cat /dev/Nulo 2024-01-29 12:47:09 -03:00 committed by Nulo
parent 3a794feb4f
commit 80c783eb84
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 { migrate } from "drizzle-orm/better-sqlite3/migrator";
import * as schema from "./schema.js"; import * as schema from "./schema.js";
import { sql } from "drizzle-orm"; import { sql } from "drizzle-orm";
import { existsSync } from "node:fs";
import { join } from "node:path";
/** /**
* @param {import("drizzle-orm/better-sqlite3").BetterSQLite3Database<schema>} db * @param {import("drizzle-orm/better-sqlite3").BetterSQLite3Database<schema>} db
*/ */
export function migrateDb(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 journal_mode = WAL;`);
db.run(sql`PRAGMA synchronous = NORMAL;`); db.run(sql`PRAGMA synchronous = NORMAL;`);
} }

View file

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