54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
/**
|
|
* SQL 마이그레이션 실행 스크립트
|
|
* 사용법: node scripts/run-migration.js
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { Pool } = require('pg');
|
|
|
|
// DATABASE_URL에서 연결 정보 파싱
|
|
const databaseUrl = process.env.DATABASE_URL || 'postgresql://postgres:ph0909!!@39.117.244.52:11132/plm';
|
|
|
|
// 데이터베이스 연결 설정
|
|
const pool = new Pool({
|
|
connectionString: databaseUrl,
|
|
});
|
|
|
|
async function runMigration() {
|
|
const client = await pool.connect();
|
|
|
|
try {
|
|
console.log('🔄 마이그레이션 시작...\n');
|
|
|
|
// SQL 파일 읽기 (Docker 컨테이너 내부 경로)
|
|
const sqlPath = '/tmp/migration.sql';
|
|
const sql = fs.readFileSync(sqlPath, 'utf8');
|
|
|
|
console.log('📄 SQL 파일 로드 완료');
|
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
|
|
|
|
// SQL 실행
|
|
await client.query(sql);
|
|
|
|
console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
console.log('✅ 마이그레이션 성공적으로 완료되었습니다!');
|
|
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
|
|
|
|
} catch (error) {
|
|
console.error('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
console.error('❌ 마이그레이션 실패:');
|
|
console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
console.error(error);
|
|
console.error('\n💡 롤백이 필요한 경우 롤백 스크립트를 실행하세요.');
|
|
process.exit(1);
|
|
} finally {
|
|
client.release();
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
// 실행
|
|
runMigration();
|
|
|