From 3231edb22a8fd8cebbbc237166a2cdc47d76c44a Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Wed, 1 May 2024 00:01:44 -0600 Subject: [PATCH] feat: add migrate file to run the migrations trought the npm command --- migration.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 migration.ts diff --git a/migration.ts b/migration.ts new file mode 100644 index 000000000..ff1b31d03 --- /dev/null +++ b/migration.ts @@ -0,0 +1,20 @@ +import { drizzle } from "drizzle-orm/postgres-js"; +import { migrate } from "drizzle-orm/postgres-js/migrator"; +import postgres from "postgres"; + +const connectionString = process.env.DATABASE_URL || ""; + +const sql = postgres(connectionString, { max: 1 }); +const db = drizzle(sql); + +await migrate(db, { migrationsFolder: "drizzle" }) + .then(() => { + console.log("Migration complete"); + sql.end(); + }) + .catch((error) => { + console.log("Migration failed", error); + }) + .finally(() => { + sql.end(); + });