From 4669e6087fb7dbda5e02eedecf57861151b512b5 Mon Sep 17 00:00:00 2001 From: Nulo Date: Mon, 29 Jan 2024 12:47:09 -0300 Subject: [PATCH] arreglar migracion cli --- db-datos/migrate-cli.js | 3 +++ db-datos/migrate.js | 7 ++++++- db-datos/package.json | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db-datos/migrate-cli.js diff --git a/db-datos/migrate-cli.js b/db-datos/migrate-cli.js new file mode 100644 index 0000000..df20787 --- /dev/null +++ b/db-datos/migrate-cli.js @@ -0,0 +1,3 @@ +import { getDb } from "./db.js"; + +getDb(); diff --git a/db-datos/migrate.js b/db-datos/migrate.js index 0419aee..74ee10e 100644 --- a/db-datos/migrate.js +++ b/db-datos/migrate.js @@ -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} 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;`); } diff --git a/db-datos/package.json b/db-datos/package.json index 262876d..d3a657f 100644 --- a/db-datos/package.json +++ b/db-datos/package.json @@ -6,7 +6,7 @@ "main": "index.js", "scripts": { "generate": "drizzle-kit generate:sqlite", - "migrate": "node db.js" + "migrate": "node migrate-cli.js" }, "keywords": [], "author": "",