Feat: agregar botones de debug para limpiar datos y exportar backup
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m6s

- Agregar botón 'LIMPIAR DATOS' que hace TRUNCATE de tablas sin borrar estructura
- Agregar botón 'EXPORTAR BACKUP' que descarga pg_dump completo de la BD
- Crear endpoint POST /api/debug/clear-data para TRUNCATE CASCADE
- Crear endpoint POST /api/debug/export-database para pg_dump con descarga
- Mantener estructura de botones temporales de debug existentes
- Incluir confirmaciones y manejo de errores apropiados
This commit is contained in:
2025-11-22 04:10:50 -06:00
parent f3a170c882
commit 2eb0cfa459
3 changed files with 240 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
/**
* ⚠️ ⚠️ ⚠️ ENDPOINT DE DEBUG - TEMPORAL ⚠️ ⚠️ ⚠️
*
* POST /api/debug/clear-data
*
* ELIMINA TODOS LOS DATOS DE LAS TABLAS (TRUNCATE) SIN BORRAR LA ESTRUCTURA
*
* ⚠️ 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'
export default defineEventHandler(async (event) => {
try {
console.log('🧹 CLEAR DATA - Eliminando todos los datos de las tablas...')
const client = await getClient()
try {
await client.query('BEGIN')
// Eliminar datos de todas las tablas en orden correcto (respetar foreign keys)
console.log(' - Truncando operacion_lotes...')
await client.query('TRUNCATE TABLE operacion_lotes CASCADE')
console.log(' - Truncando operaciones...')
await client.query('TRUNCATE TABLE operaciones CASCADE')
console.log(' - Truncando lotes...')
await client.query('TRUNCATE TABLE lotes CASCADE')
await client.query('COMMIT')
console.log('✅ Datos eliminados exitosamente. Las tablas están vacías pero la estructura se mantiene.')
return {
success: true,
message: 'Datos eliminados exitosamente. Las tablas están vacías.',
}
} catch (error) {
await client.query('ROLLBACK')
throw error
} finally {
client.release()
}
} catch (error: any) {
console.error('❌ Error limpiando datos:', error)
throw createError({
statusCode: 500,
statusMessage: 'Error limpiando datos',
data: { message: error.message },
})
}
})