2026-03-04 18:42:58 +01:00
|
|
|
import { Pool } from "pg";
|
|
|
|
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
|
|
|
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
|
|
|
|
import path from "path";
|
|
|
|
|
|
|
|
|
|
const pool = new Pool({
|
|
|
|
|
connectionString: process.env.DATABASE_URL || "postgresql://sexy:sexy@localhost:5432/sexy",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const db = drizzle(pool);
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
|
console.log("Running schema migrations...");
|
2026-03-04 20:31:18 +01:00
|
|
|
// In dev (tsx): __dirname = src/scripts → migrations are at src/migrations
|
|
|
|
|
// In prod (node dist): __dirname = dist/scripts → migrations are at ../../migrations (package root)
|
|
|
|
|
const migrationsFolder = __dirname.includes("/src/")
|
|
|
|
|
? path.join(__dirname, "../migrations")
|
|
|
|
|
: path.join(__dirname, "../../migrations");
|
2026-03-04 18:42:58 +01:00
|
|
|
await migrate(db, { migrationsFolder });
|
|
|
|
|
console.log("Schema migrations complete.");
|
|
|
|
|
await pool.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main().catch((err) => {
|
|
|
|
|
console.error("Migration failed:", err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|