import { Pool } from 'pg' import * as fs from 'fs' import path from 'path' const migrate = require('node-pg-migrate') // Database connection configuration const dbConfig = { user: 'your_user', host: 'localhost', database: 'your_database', password: 'your_password', port: 5432, } const pool = new Pool(dbConfig) const migrations = [] fs.readdirSync(__dirname) .filter((file) => { // Filter out hidden files, index.js itself, and non-JS files return ( file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js' ) }) .forEach((file) => { // Require each file and add its default export to the list const migration = require(path.join(__dirname, file)) migrations.push(migration) }) async function runMigrations() { try { await migrate.run(migrations, pool) console.log('Migrations completed successfully!') } catch (error) { console.error('Migration failed:', error) } } runMigrations()