modified: backend/src/config/database.ts
modified: backend/src/server.ts
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { Pool } from 'pg';
|
||||
import { config } from './environment';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
// Main database pool for KIS API Builder metadata
|
||||
export const mainPool = new Pool({
|
||||
@@ -28,3 +30,24 @@ export const initializeDatabase = async () => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const runMigrations = async () => {
|
||||
console.log('🔄 Running migrations...');
|
||||
try {
|
||||
const migrationsDir = path.join(__dirname, '../migrations');
|
||||
const files = fs.readdirSync(migrationsDir)
|
||||
.filter(f => f.endsWith('.sql'))
|
||||
.sort();
|
||||
|
||||
for (const file of files) {
|
||||
console.log(` 📄 ${file}`);
|
||||
const sql = fs.readFileSync(path.join(migrationsDir, file), 'utf-8');
|
||||
await mainPool.query(sql);
|
||||
}
|
||||
|
||||
console.log('✅ Migrations completed');
|
||||
} catch (error) {
|
||||
console.error('❌ Migration failed:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user