-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.ts
More file actions
27 lines (20 loc) · 731 Bytes
/
Copy pathmigrate.ts
File metadata and controls
27 lines (20 loc) · 731 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
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';
async function runMigrations() {
if (!process.env.DATABASE_URL) {
throw new Error('DATABASE_URL is missing!');
}
console.log('Waiting for database connection...');
const migrationClient = postgres(process.env.DATABASE_URL, { max: 1 });
const db = drizzle(migrationClient);
console.log('Starting migrations...');
await migrate(db, { migrationsFolder: './drizzle' });
console.log('Migrations completed successfully!');
await migrationClient.end();
process.exit(0);
}
runMigrations().catch((err) => {
console.error('Error while migrating: ', err);
process.exit(1);
});