Begin payment logic and tests

This commit is contained in:
jwinterm
2025-09-27 08:45:22 -04:00
parent 4ad063f735
commit e3915dcde2
29 changed files with 564835 additions and 853 deletions
+12 -2
View File
@@ -63,6 +63,9 @@ class DatabaseManager {
*/
async runMigrations() {
try {
// Simple migration ledger
await this.pool.query(`CREATE TABLE IF NOT EXISTS schema_migrations (filename TEXT PRIMARY KEY, applied_at TIMESTAMP DEFAULT NOW())`);
const migrationsPath = path.join(__dirname, '../migrations');
const files = await fs.readdir(migrationsPath);
const sqlFiles = files.filter(file => file.endsWith('.sql')).sort();
@@ -70,15 +73,22 @@ class DatabaseManager {
console.log(`📁 Found ${sqlFiles.length} migration files`);
for (const file of sqlFiles) {
// Skip if already applied
const existing = await this.pool.query(`SELECT 1 FROM schema_migrations WHERE filename = $1`, [file]);
if (existing.rowCount > 0) {
console.log(`⏩ Skipping already applied migration: ${file}`);
continue;
}
const filePath = path.join(migrationsPath, file);
const sql = await fs.readFile(filePath, 'utf8');
console.log(`🔄 Running migration: ${file}`);
await this.pool.query(sql);
await this.pool.query(`INSERT INTO schema_migrations (filename) VALUES ($1)`, [file]);
console.log(`✅ Migration completed: ${file}`);
}
console.log('✅ All migrations completed successfully');
console.log('✅ Migration phase complete');
} catch (error) {
console.error('❌ Migration failed:', error.message);
throw error;