2025-09-21 12:03:29 +01:00
|
|
|
import { config } from 'dotenv';
|
|
|
|
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
|
|
|
import { migrate } from 'drizzle-orm/postgres-js/migrator';
|
|
|
|
|
import postgres from 'postgres';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
|
|
|
|
config({
|
2025-09-21 12:03:29 +01:00
|
|
|
path: '.env.local',
|
2024-10-11 18:00:22 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const runMigrate = async () => {
|
|
|
|
|
if (!process.env.POSTGRES_URL) {
|
2025-09-21 12:03:29 +01:00
|
|
|
throw new Error('POSTGRES_URL is not defined');
|
2024-10-11 18:00:22 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const connection = postgres(process.env.POSTGRES_URL, { max: 1 });
|
|
|
|
|
const db = drizzle(connection);
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
console.log('⏳ Running migrations...');
|
2024-10-11 18:00:22 +05:30
|
|
|
|
|
|
|
|
const start = Date.now();
|
2025-09-21 12:03:29 +01:00
|
|
|
await migrate(db, { migrationsFolder: './lib/db/migrations' });
|
2024-10-11 18:00:22 +05:30
|
|
|
const end = Date.now();
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
console.log('✅ Migrations completed in', end - start, 'ms');
|
2024-10-11 18:00:22 +05:30
|
|
|
process.exit(0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
runMigrate().catch((err) => {
|
2025-09-21 12:03:29 +01:00
|
|
|
console.error('❌ Migration failed');
|
2024-10-11 18:00:22 +05:30
|
|
|
console.error(err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|