chore: add postgres schema migrations
This commit is contained in:
23
scripts/migrate.ts
Normal file
23
scripts/migrate.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import "dotenv/config";
|
||||
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
||||
|
||||
import { createDbClient } from "../packages/db/src/client.js";
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!databaseUrl) {
|
||||
throw new Error("DATABASE_URL is required to run migrations");
|
||||
}
|
||||
|
||||
const migrationsFolder = fileURLToPath(new URL("../packages/db/src/migrations", import.meta.url));
|
||||
|
||||
const client = createDbClient(databaseUrl);
|
||||
|
||||
try {
|
||||
await migrate(client.db, { migrationsFolder });
|
||||
console.log(`Migrations applied from ${migrationsFolder}`);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
Reference in New Issue
Block a user