56 lines
1.7 KiB
JavaScript
Executable file
56 lines
1.7 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
/**
|
|
* Script para ejecutar la migración 004: Glossary Schema (TICKET-007)
|
|
* Ejecuta: backend/database/migrations/004_create_glossary_schema.sql
|
|
*/
|
|
|
|
import { readFile } from 'fs/promises';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { query } from '../config/database.js';
|
|
import 'dotenv/config';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const migrationPath = join(__dirname, '../database/migrations/004_create_glossary_schema.sql');
|
|
|
|
async function runMigration() {
|
|
try {
|
|
console.log('🔧 Ejecutando migración: Glossary Schema (tes_content.glossary_terms)\n');
|
|
|
|
const migrationSql = await readFile(migrationPath, 'utf-8');
|
|
|
|
console.log('📝 Ejecutando SQL...\n');
|
|
|
|
try {
|
|
await query(migrationSql);
|
|
console.log('✅ Migración ejecutada correctamente\n');
|
|
} catch (error) {
|
|
if (error.code === '42P07' || error.code === '42710' || error.message?.includes('already exists')) {
|
|
console.log('⚠️ Algunos objetos ya existen (normal si ya se ejecutó antes)\n');
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
const tablesResult = await query(`
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'tes_content' AND table_name = 'glossary_terms'
|
|
`);
|
|
|
|
if (tablesResult.rows.length > 0) {
|
|
console.log(' ✅ tabla glossary_terms creada');
|
|
} else {
|
|
console.log(' ⚠️ Tabla glossary_terms no encontrada');
|
|
}
|
|
|
|
console.log('\n✅ Migración del glosario completada.\n');
|
|
} catch (error) {
|
|
console.error('❌ Error ejecutando migración:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
runMigration();
|