-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.ts
More file actions
32 lines (25 loc) · 806 Bytes
/
migrate.ts
File metadata and controls
32 lines (25 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { drizzle } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
import dotenv from "dotenv";
dotenv.config({
path: ".env.local",
});
const runMigrate = async () => {
if (!process.env.POSTGRES_URL) {
throw new Error("POSTGRES_URL is not defined");
}
const connection = postgres(process.env.POSTGRES_URL, { max: 1 });
const db = drizzle(connection);
console.log("⏳ Running migrations...");
const start = Date.now();
await migrate(db, { migrationsFolder: "./drizzle" });
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);
});