fp/services/migrations/index.js

32 lines
849 B
JavaScript
Raw Normal View History

2024-07-30 20:34:25 +00:00
import {migrate} from 'postgres-migrations'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'url';
import 'dotenv/config'
2024-08-17 02:42:44 +00:00
2024-07-30 20:34:25 +00:00
const __dirname = dirname(fileURLToPath(import.meta.url));
if (!process.env.DATABASE_PASSWORD) throw new Error('DATABASE_PASSWORD is missing in env');
async function main() {
const dbConfig = {
2024-08-04 16:40:13 +00:00
database: "futureporn",
2024-07-30 20:34:25 +00:00
user: "postgres",
password: process.env.DATABASE_PASSWORD,
host: 'postgresql-primary.futureporn.svc.cluster.local',
port: 5432,
// Default: false for backwards-compatibility
// This might change!
ensureDatabaseExists: true,
// Default: "postgres"
// Used when checking/creating "database-name"
2024-07-30 20:50:30 +00:00
defaultDatabase: "postgres"
2024-07-30 20:34:25 +00:00
}
2024-08-17 02:42:44 +00:00
await migrate(dbConfig, path.join(__dirname, "./migrations/"), { logger: console.log })
2024-07-30 20:34:25 +00:00
}
2024-08-07 01:13:58 +00:00
await main()