Created
August 28, 2023 21:09
-
-
Save diboune/943f85c5b1bf079a27e5cbff3e1b3b8a to your computer and use it in GitHub Desktop.
migrator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sql } from "@vercel/postgres"; | |
import { drizzle } from "drizzle-orm/vercel-postgres"; | |
import { migrate } from "drizzle-orm/vercel-postgres/migrator"; | |
import "dotenv/config"; | |
async function runMigrate() { | |
if (!process.env.POSTGRES_DATABASE) { | |
throw new Error("POSTGRES_DATABASE is not defined"); | |
} | |
const db = drizzle(sql); | |
console.log("Running migrations..."); | |
const start = Date.now(); | |
await migrate(db, { migrationsFolder: "app/database/migrations" }); | |
const end = Date.now(); | |
console.log(`✅ Migrations completed in ${end - start}ms`); | |
process.exit(0); | |
} | |
runMigrate().catch((err) => { | |
console.error("❌ Migration failed"); | |
console.error(err); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment