working on first setup of pg migrations

This commit is contained in:
2026-05-10 19:51:13 -07:00
parent 3cdec698ef
commit 5318a1eb4a
5 changed files with 121 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
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()