66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
/**
|
|
* Script para crear el schema completo tes_content
|
|
* Ejecuta el SQL del schema completo
|
|
*/
|
|
|
|
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 schemaPath = join(__dirname, '../../docs/SERVER_DATABASE_SCHEMA.sql');
|
|
|
|
async function createFullSchema() {
|
|
try {
|
|
console.log('🔧 Creando schema completo tes_content...\n');
|
|
|
|
// Leer el SQL completo
|
|
const schemaSql = await readFile(schemaPath, 'utf-8');
|
|
|
|
console.log('📝 Ejecutando SQL completo...\n');
|
|
|
|
try {
|
|
// Ejecutar todo el SQL de una vez
|
|
await query(schemaSql);
|
|
console.log('✅ SQL ejecutado correctamente\n');
|
|
} catch (error) {
|
|
// Ignorar errores de "ya existe"
|
|
if (error.code === '42P07' || error.code === '42710' || error.message.includes('already exists')) {
|
|
console.log('⚠️ Algunos objetos ya existen (esto es normal)\n');
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
// Verificar tablas creadas
|
|
console.log('📊 Verificando tablas creadas...');
|
|
const tablesResult = await query(`
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'tes_content'
|
|
ORDER BY table_name
|
|
`);
|
|
|
|
if (tablesResult.rows.length > 0) {
|
|
console.log(' Tablas encontradas:');
|
|
tablesResult.rows.forEach(row => {
|
|
console.log(` ✅ ${row.table_name}`);
|
|
});
|
|
} else {
|
|
console.log(' ⚠️ No se encontraron tablas');
|
|
}
|
|
|
|
console.log('\n✅ Schema tes_content creado correctamente!');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error creando schema:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
createFullSchema();
|
|
|