- P2606: Plan v1.1 EN EJECUCIÓN. Fases 1-3 completadas. - Ficha nodo srvv-nginx-rm.md. P2606 en adn/07_proyectos.md. - Incluye cambios acumulados de sesiones anteriores.
93 lines
3.6 KiB
PL/PgSQL
93 lines
3.6 KiB
PL/PgSQL
-- dtic-BITACORAs - Esquema de Base de Datos
|
|
-- Formato I-F-D-E (Inicio, Fin, Descripción, Estado)
|
|
|
|
CREATE SCHEMA IF NOT EXISTS bitacoras;
|
|
|
|
-- Nodos del sistema (servidores, VMs, PCs)
|
|
CREATE TABLE bitacoras.nodos (
|
|
id SERIAL PRIMARY KEY,
|
|
nombre VARCHAR(50) NOT NULL UNIQUE,
|
|
ip VARCHAR(45),
|
|
tipo VARCHAR(20) DEFAULT 'servidor',
|
|
descripcion TEXT,
|
|
activo BOOLEAN DEFAULT true,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Bitácoras diarias
|
|
CREATE TABLE bitacoras.bitacoras (
|
|
id SERIAL PRIMARY KEY,
|
|
fecha DATE NOT NULL UNIQUE,
|
|
resumen TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Temas (agrupadores de entradas por nodo)
|
|
CREATE TABLE bitacoras.temas (
|
|
id SERIAL PRIMARY KEY,
|
|
id_tema VARCHAR(20) NOT NULL,
|
|
titulo VARCHAR(200) NOT NULL,
|
|
estado VARCHAR(10) DEFAULT '⏳',
|
|
descripcion TEXT,
|
|
bitacora_id INTEGER REFERENCES bitacoras.bitacoras(id) ON DELETE CASCADE,
|
|
nodo_id INTEGER REFERENCES bitacoras.nodos(id),
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Entradas cronológicas (formato I-F-D-E)
|
|
CREATE TABLE bitacoras.entradas (
|
|
id SERIAL PRIMARY KEY,
|
|
inicio TIME NOT NULL,
|
|
fin TIME,
|
|
descripcion TEXT NOT NULL,
|
|
estado VARCHAR(10) DEFAULT '⏳',
|
|
modo CHAR(1) DEFAULT 'P' CHECK (modo IN ('P', 'R')),
|
|
es_ia BOOLEAN DEFAULT false,
|
|
doc_path TEXT,
|
|
tema_id INTEGER REFERENCES bitacoras.temas(id) ON DELETE CASCADE,
|
|
bitacora_id INTEGER REFERENCES bitacoras.bitacoras(id) ON DELETE CASCADE,
|
|
nodo_id INTEGER REFERENCES bitacoras.nodos(id),
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Índices
|
|
CREATE INDEX idx_bitacoras_fecha ON bitacoras.bitacoras(fecha);
|
|
CREATE INDEX idx_entradas_bitacora ON bitacoras.entradas(bitacora_id);
|
|
CREATE INDEX idx_entradas_nodo ON bitacoras.entradas(nodo_id);
|
|
CREATE INDEX idx_temas_bitacora ON bitacoras.temas(bitacora_id);
|
|
|
|
-- Trigger para updated_at
|
|
CREATE OR REPLACE FUNCTION bitacoras.update_timestamp()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
NEW.updated_at = CURRENT_TIMESTAMP;
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE TRIGGER trg_nodos_updated BEFORE UPDATE ON bitacoras.nodos
|
|
FOR EACH ROW EXECUTE FUNCTION bitacoras.update_timestamp();
|
|
CREATE TRIGGER trg_bitacoras_updated BEFORE UPDATE ON bitacoras.bitacoras
|
|
FOR EACH ROW EXECUTE FUNCTION bitacoras.update_timestamp();
|
|
CREATE TRIGGER trg_temas_updated BEFORE UPDATE ON bitacoras.temas
|
|
FOR EACH ROW EXECUTE FUNCTION bitacoras.update_timestamp();
|
|
CREATE TRIGGER trg_entradas_updated BEFORE UPDATE ON bitacoras.entradas
|
|
FOR EACH ROW EXECUTE FUNCTION bitacoras.update_timestamp();
|
|
|
|
-- Datos semilla: Nodos del proyecto
|
|
INSERT INTO bitacoras.nodos (nombre, ip, tipo, descripcion) VALUES
|
|
('srv-ns8', '10.0.10.8', 'servidor', 'Nodo central de gestión, GIT y Dashboard'),
|
|
('srv-dasu', '10.0.10.205', 'hipervisor', 'Hipervisor Proxmox VE (DASUTEN)'),
|
|
('dc-dasuten', '10.0.100.10', 'vm', 'Controlador de Dominio AD DS + DNS'),
|
|
('sql-dasuten', '10.0.100.11', 'vm', 'Motor SQL Server 2019 Core'),
|
|
('pcv-dasu0', '10.0.100.12', 'vm', 'VM de pruebas Win 10 LTSC'),
|
|
('pc-dasu0', NULL, 'pc', 'PC física cliente oficina DASUTeN'),
|
|
('srv-pmox1', '10.0.10.201', 'hipervisor', 'Pool master Proxmox'),
|
|
('srv-pmox2', '10.0.10.202', 'hipervisor', 'Nodo Proxmox secundario'),
|
|
('srv-pmox3', '10.0.10.203', 'hipervisor', 'Nodo Proxmox terciario (64GB RAM)'),
|
|
('srv-xen1', '10.0.10.23', 'hipervisor', 'Citrix XenServer 7.0 (Legacy)');
|