Agregar botones de debug temporales para gestión de BD
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 16s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 16s
⚠️ CÓDIGO TEMPORAL - NO ELIMINAR SIN CONSULTAR ⚠️ Backend: - POST /api/debug/reset-database - Borra todos los datos - POST /api/debug/seed-database - Carga datos de ejemplo Frontend: - Card rojo con advertencias notorias - Botones: 🗑️ BORRAR TODA LA BD y 🌱 CARGAR DATOS DE EJEMPLO - Confirmación antes de resetear - Estados de loading - Alertas de éxito/error Todos los archivos marcados con comentarios muy visibles: ⚠️⚠️⚠️ NO ELIMINAR SIN CONSULTAR A DARIO/DRAGANEL/NUCLEO000 ⚠️⚠️⚠️ Útil para desarrollo y debugging del sistema de trazabilidad.
This commit is contained in:
56
nuxt4/server/api/debug/seed-database.post.ts
Normal file
56
nuxt4/server/api/debug/seed-database.post.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* ⚠️ ⚠️ ⚠️ ENDPOINT DE DEBUG - TEMPORAL ⚠️ ⚠️ ⚠️
|
||||
*
|
||||
* POST /api/debug/seed-database
|
||||
*
|
||||
* CARGA LOS DATOS DE EJEMPLO EN LA BASE DE DATOS
|
||||
*
|
||||
* ⚠️ NO ELIMINAR SIN CONSULTAR A DARIO/DRAGANEL/NUCLEO000 ⚠️
|
||||
*
|
||||
* Este endpoint fue creado para desarrollo y debugging.
|
||||
* Antes de eliminarlo, preguntar si todavía es necesario.
|
||||
*/
|
||||
|
||||
import { getClient } from '../../utils/db'
|
||||
import { readFile } from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
console.log('🌱 SEED DATABASE - Cargando datos de ejemplo...')
|
||||
|
||||
const client = await getClient()
|
||||
|
||||
try {
|
||||
// Leer el archivo de seed
|
||||
const seedPath = join(process.cwd(), 'server', 'database', '02_seed.sql')
|
||||
const seedSQL = await readFile(seedPath, 'utf-8')
|
||||
|
||||
await client.query('BEGIN')
|
||||
|
||||
// Ejecutar el script completo de seed
|
||||
await client.query(seedSQL)
|
||||
|
||||
await client.query('COMMIT')
|
||||
|
||||
console.log('✅ Datos de ejemplo cargados exitosamente')
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Datos de ejemplo cargados: 10 lotes, 7 operaciones, 16 relaciones',
|
||||
}
|
||||
} catch (error) {
|
||||
await client.query('ROLLBACK')
|
||||
throw error
|
||||
} finally {
|
||||
client.release()
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('❌ Error cargando datos de ejemplo:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Error cargando datos de ejemplo',
|
||||
data: { message: error.message },
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user