mirror of
https://github.com/d0zingcat/alert-message-center.git
synced 2026-05-21 07:26:44 +00:00
feat: make db migration automatically
Signed-off-by: d0zingcat <iamtangli42@gmail.com>
This commit is contained in:
26
apps/server/src/db/migrate.ts
Normal file
26
apps/server/src/db/migrate.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
||||
import postgres from "postgres";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const connectionString =
|
||||
process.env.DATABASE_URL ||
|
||||
"postgres://postgres:password@localhost:5432/alert_message_center";
|
||||
|
||||
async function main() {
|
||||
console.log("⏳ Running migrations...");
|
||||
const sql = postgres(connectionString, { max: 1 });
|
||||
const db = drizzle(sql, { schema });
|
||||
|
||||
try {
|
||||
await migrate(db, { migrationsFolder: "./drizzle" });
|
||||
console.log("✅ Migrations completed!");
|
||||
} catch (error) {
|
||||
console.error("❌ Migration failed:", error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await sql.end();
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user