backend y front trabajar por version de historial de cambios
This commit is contained in:
39
migrations/add_inspection_audit_log.sql
Normal file
39
migrations/add_inspection_audit_log.sql
Normal file
@@ -0,0 +1,39 @@
|
||||
-- Migración: Agregar sistema de auditoría para edición de inspecciones
|
||||
-- Fecha: 2025-11-25
|
||||
-- Descripción: Crea tabla de auditoría para rastrear todos los cambios en inspecciones y respuestas
|
||||
|
||||
-- Crear tabla de auditoría
|
||||
CREATE TABLE IF NOT EXISTS inspection_audit_log (
|
||||
id SERIAL PRIMARY KEY,
|
||||
inspection_id INTEGER NOT NULL REFERENCES inspections(id) ON DELETE CASCADE,
|
||||
answer_id INTEGER REFERENCES answers(id) ON DELETE CASCADE,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||
action VARCHAR(50) NOT NULL, -- created, updated, deleted, status_changed
|
||||
entity_type VARCHAR(50) NOT NULL, -- inspection, answer
|
||||
field_name VARCHAR(100), -- Campo modificado
|
||||
old_value TEXT, -- Valor anterior
|
||||
new_value TEXT, -- Valor nuevo
|
||||
comment TEXT, -- Comentario del cambio
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Crear índices para mejorar rendimiento
|
||||
CREATE INDEX idx_audit_log_inspection ON inspection_audit_log(inspection_id);
|
||||
CREATE INDEX idx_audit_log_answer ON inspection_audit_log(answer_id);
|
||||
CREATE INDEX idx_audit_log_user ON inspection_audit_log(user_id);
|
||||
CREATE INDEX idx_audit_log_created_at ON inspection_audit_log(created_at DESC);
|
||||
|
||||
-- Comentarios para documentación
|
||||
COMMENT ON TABLE inspection_audit_log IS 'Registro de auditoría de cambios en inspecciones y respuestas. Registra quién, cuándo y qué cambió.';
|
||||
COMMENT ON COLUMN inspection_audit_log.action IS 'Tipo de acción: created, updated, deleted, status_changed';
|
||||
COMMENT ON COLUMN inspection_audit_log.entity_type IS 'Tipo de entidad modificada: inspection, answer';
|
||||
COMMENT ON COLUMN inspection_audit_log.field_name IS 'Nombre del campo que fue modificado';
|
||||
COMMENT ON COLUMN inspection_audit_log.old_value IS 'Valor anterior del campo';
|
||||
COMMENT ON COLUMN inspection_audit_log.new_value IS 'Valor nuevo del campo';
|
||||
COMMENT ON COLUMN inspection_audit_log.comment IS 'Comentario del administrador sobre por qué realizó el cambio';
|
||||
|
||||
-- Verificar que la migración se ejecutó correctamente
|
||||
SELECT 'Tabla inspection_audit_log creada exitosamente' AS status;
|
||||
|
||||
-- Opcional: Ver estructura de la tabla
|
||||
\d inspection_audit_log
|
||||
Reference in New Issue
Block a user