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
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:
@@ -71,6 +71,22 @@
|
||||
>
|
||||
🌱 CARGAR DATOS DE EJEMPLO
|
||||
</UButton>
|
||||
<UButton
|
||||
@click="clearData"
|
||||
color="yellow"
|
||||
variant="solid"
|
||||
:loading="clearingData"
|
||||
>
|
||||
🧹 LIMPIAR DATOS (solo datos)
|
||||
</UButton>
|
||||
<UButton
|
||||
@click="exportDatabase"
|
||||
color="blue"
|
||||
variant="solid"
|
||||
:loading="exportingDB"
|
||||
>
|
||||
💾 EXPORTAR BACKUP
|
||||
</UButton>
|
||||
</div>
|
||||
<p class="text-xs text-red-600 dark:text-red-400 mt-2">
|
||||
Resultados en consola (F12). Recarga la página después de usar estos botones.
|
||||
@@ -441,6 +457,8 @@ onMounted(() => {
|
||||
// NO ELIMINAR SIN CONSULTAR A DARIO/DRAGANEL/NUCLEO000
|
||||
const resettingDB = ref(false)
|
||||
const seedingDB = ref(false)
|
||||
const clearingData = ref(false)
|
||||
const exportingDB = ref(false)
|
||||
|
||||
const resetDatabase = async () => {
|
||||
if (!confirm('⚠️ ADVERTENCIA: Esto BORRARÁ TODOS LOS DATOS de la base de datos.\n\n¿Estás seguro de continuar?')) {
|
||||
@@ -491,6 +509,71 @@ const seedDatabase = async () => {
|
||||
seedingDB.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const clearData = async () => {
|
||||
if (!confirm('⚠️ ADVERTENCIA: Esto ELIMINARÁ TODOS LOS DATOS de las tablas (TRUNCATE) pero mantendrá la estructura.\n\n¿Estás seguro de continuar?')) {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('🧹 === LIMPIANDO DATOS DE TABLAS ===')
|
||||
clearingData.value = true
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/debug/clear-data', {
|
||||
method: 'POST',
|
||||
})
|
||||
const data = await response.json()
|
||||
console.log('Status:', response.status)
|
||||
console.log('Respuesta:', data)
|
||||
|
||||
if (data.success) {
|
||||
alert('✅ Datos eliminados exitosamente. Las tablas están vacías.\n\nRecarga la página para ver los cambios.')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Error:', error)
|
||||
alert('❌ Error limpiando datos. Ver consola.')
|
||||
} finally {
|
||||
clearingData.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const exportDatabase = async () => {
|
||||
console.log('💾 === EXPORTANDO BACKUP DE BASE DE DATOS ===')
|
||||
exportingDB.value = true
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/debug/export-database', {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Error en la exportación')
|
||||
}
|
||||
|
||||
// Descargar el archivo SQL
|
||||
const blob = await response.blob()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
|
||||
// Nombre del archivo con timestamp
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5)
|
||||
a.download = `backup-seguidordelotes-${timestamp}.sql`
|
||||
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
document.body.removeChild(a)
|
||||
|
||||
console.log('✅ Backup descargado exitosamente')
|
||||
alert('✅ Backup de base de datos descargado exitosamente.')
|
||||
} catch (error) {
|
||||
console.error('❌ Error:', error)
|
||||
alert('❌ Error exportando backup. Ver consola.')
|
||||
} finally {
|
||||
exportingDB.value = false
|
||||
}
|
||||
}
|
||||
// ⚠️⚠️⚠️ FIN FUNCIONES DE DEBUG ⚠️⚠️⚠️
|
||||
|
||||
// Funciones de prueba de API
|
||||
|
||||
Reference in New Issue
Block a user