fp/services/migrations/index.js

29 lines
815 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'
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 = {
database: "postgrest",
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"
defaultDatabase: "postgrest"
}
await migrate(dbConfig, path.join(__dirname, "./migrations/"))
}
main()