47 lines
2.6 KiB
SQL
47 lines
2.6 KiB
SQL
-- ============================================================
|
|
-- MIGRACIÓN DTIC MESA DE PARTE - VERSIÓN 2.0
|
|
-- ============================================================
|
|
|
|
USE `gestion_documentos`;
|
|
|
|
-- 1. Crear tabla de Unidades DTIC
|
|
CREATE TABLE IF NOT EXISTS `unidades_dtic` (
|
|
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`nombre` VARCHAR(100) NOT NULL,
|
|
`siglas` VARCHAR(20) DEFAULT NULL,
|
|
`icono` VARCHAR(50) DEFAULT 'fa-building',
|
|
`responsable_id` INT UNSIGNED DEFAULT NULL,
|
|
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_unidad_nombre` (`nombre`),
|
|
CONSTRAINT `fk_unidad_responsable` FOREIGN KEY (`responsable_id`) REFERENCES `usuarios` (`id`) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
-- 2. Insertar Unidades DTIC solicitadas
|
|
INSERT IGNORE INTO `unidades_dtic` (`nombre`, `siglas`, `icono`) VALUES
|
|
('Programación', 'PROG', 'fa-code'),
|
|
('Administración', 'ADM', 'fa-file-invoice-dollar'),
|
|
('Personal', 'PERS', 'fa-users'),
|
|
('Adiestramiento', 'ADIE', 'fa-user-graduate'),
|
|
('Centro de Datos', 'DATA', 'fa-server'),
|
|
('Auditoría', 'AUDI', 'fa-magnifying-glass-chart'),
|
|
('Desarrollo', 'DES', 'fa-laptop-code'),
|
|
('Agraz', 'AGRAZ', 'fa-shield-halved');
|
|
|
|
-- 3. Actualizar tabla usuarios para incluir unidad_id
|
|
ALTER TABLE `usuarios` ADD COLUMN IF NOT EXISTS `unidad_id` INT UNSIGNED DEFAULT NULL AFTER `rol_id`;
|
|
ALTER TABLE `usuarios` ADD CONSTRAINT `fk_usuario_unidad` FOREIGN KEY (`unidad_id`) REFERENCES `unidades_dtic` (`id`) ON DELETE SET NULL;
|
|
|
|
-- 4. Actualizar tabla oficios para flujo de Mesa de Parte
|
|
ALTER TABLE `oficios` ADD COLUMN IF NOT EXISTS `unidad_destino_id` INT UNSIGNED DEFAULT NULL AFTER `destinatario`;
|
|
ALTER TABLE `oficios` ADD CONSTRAINT `fk_oficio_unidad_destino` FOREIGN KEY (`unidad_destino_id`) REFERENCES `unidades_dtic` (`id`) ON DELETE SET NULL;
|
|
|
|
-- 5. Expandir ENUM de estado en oficios (Asegurar que existan los nuevos estados)
|
|
-- Nota: En MySQL no se puede usar ADD COLUMN IF NOT EXISTS para modificar un ENUM fácilmente de forma segura sin recrear o usar ALTER.
|
|
-- Usaremos un ALTER directo asumiendo el esquema base.
|
|
ALTER TABLE `oficios` MODIFY COLUMN `estado` ENUM('recibido','en_proceso','respondido','vencido','archivado','cumplido','verificado') NOT NULL DEFAULT 'recibido';
|
|
|
|
-- 6. Insertar Rol "Super Administrator" si no existe (con acceso total++)
|
|
INSERT IGNORE INTO `roles` (`nombre`, `descripcion`, `permisos`) VALUES
|
|
('superadmin', 'Control absoluto del sistema y registros protegidos', '{"oficios":"CRUD","usuarios":"CRUD","reportes":true,"respaldo":true,"papelera_fisica":true,"config_alertas":true,"maestros":true}');
|