-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
109 lines (100 loc) · 6.44 KB
/
schema.sql
File metadata and controls
109 lines (100 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
-- ============================================================
-- schema.sql — Rack Manager DCIM
-- Banco: rack_manager
-- Compatível com MySQL 5.7+ / MariaDB 10.3+
-- ============================================================
CREATE DATABASE IF NOT EXISTS rack_manager
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
USE rack_manager;
-- ------------------------------------------------------------
-- RACKS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS racks (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
nome VARCHAR(100) NOT NULL,
localizacao VARCHAR(200) NOT NULL DEFAULT '',
sala VARCHAR(100) NOT NULL DEFAULT '',
fila VARCHAR(50) NOT NULL DEFAULT '',
posicao VARCHAR(50) NOT NULL DEFAULT '',
capacidade_u TINYINT UNSIGNED NOT NULL DEFAULT 42,
descricao TEXT,
criado_em DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
INDEX idx_sala (sala),
INDEX idx_nome (nome)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ------------------------------------------------------------
-- ATIVOS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS ativos (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
rack_id INT UNSIGNED NOT NULL,
hostname VARCHAR(150) NOT NULL,
tipo ENUM('servidor','switch','pdu','patch_panel','firewall','storage','kvm','outro') NOT NULL DEFAULT 'servidor',
fabricante VARCHAR(100) NOT NULL DEFAULT '',
modelo VARCHAR(150) NOT NULL DEFAULT '',
numero_serie VARCHAR(150) NOT NULL DEFAULT '',
posicao_u TINYINT UNSIGNED NOT NULL DEFAULT 1,
altura_u TINYINT UNSIGNED NOT NULL DEFAULT 1,
ip_gerencia VARCHAR(45) NOT NULL DEFAULT '',
status ENUM('ativo','manutencao','descomissionado','reservado') NOT NULL DEFAULT 'ativo',
observacoes TEXT,
criado_em DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
atualizado_em DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT fk_ativo_rack FOREIGN KEY (rack_id) REFERENCES racks(id) ON DELETE CASCADE,
INDEX idx_rack (rack_id),
INDEX idx_tipo (tipo),
INDEX idx_status(status),
INDEX idx_ip (ip_gerencia)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ------------------------------------------------------------
-- CABOS
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS cabos (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
origem_ativo_id INT UNSIGNED NOT NULL,
origem_porta VARCHAR(50) NOT NULL DEFAULT '',
destino_ativo_id INT UNSIGNED NOT NULL,
destino_porta VARCHAR(50) NOT NULL DEFAULT '',
tipo_cabo ENUM('ethernet_cat5e','ethernet_cat6','ethernet_cat6a','fibra_om3','fibra_om4','fibra_os2','dac','power','console','outro') NOT NULL DEFAULT 'ethernet_cat6',
comprimento_m DECIMAL(6,2) UNSIGNED DEFAULT NULL,
cor VARCHAR(30) NOT NULL DEFAULT 'azul',
criado_em DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT fk_cabo_origem FOREIGN KEY (origem_ativo_id) REFERENCES ativos(id) ON DELETE CASCADE,
CONSTRAINT fk_cabo_destino FOREIGN KEY (destino_ativo_id) REFERENCES ativos(id) ON DELETE CASCADE,
INDEX idx_origem (origem_ativo_id),
INDEX idx_destino (destino_ativo_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ============================================================
-- DADOS DE EXEMPLO
-- ============================================================
INSERT INTO racks (nome, localizacao, sala, fila, posicao, capacidade_u, descricao) VALUES
('RACK-A01', 'DC São Paulo — Sala A, Fila 1, Pos 1', 'Sala A', 'Fila 1', 'Pos 1', 42, 'Rack de servidores de aplicação principal'),
('RACK-A02', 'DC São Paulo — Sala A, Fila 1, Pos 2', 'Sala A', 'Fila 1', 'Pos 2', 42, 'Rack de servidores de banco de dados'),
('RACK-B01', 'DC São Paulo — Sala B, Fila 1, Pos 1', 'Sala B', 'Fila 1', 'Pos 1', 42, 'Rack de rede e segurança'),
('RACK-B02', 'DC São Paulo — Sala B, Fila 2, Pos 1', 'Sala B', 'Fila 2', 'Pos 1', 42, 'Rack de storage e backup');
INSERT INTO ativos (rack_id, hostname, tipo, fabricante, modelo, numero_serie, posicao_u, altura_u, ip_gerencia, status, observacoes) VALUES
-- RACK-A01 (id=1)
(1, 'APP-SRV-01', 'servidor', 'Dell', 'PowerEdge R740', 'SN-DELL-001', 2, 2, '10.10.1.11', 'ativo', 'Servidor web principal'),
(1, 'APP-SRV-02', 'servidor', 'Dell', 'PowerEdge R740', 'SN-DELL-002', 4, 2, '10.10.1.12', 'ativo', 'Servidor web secundário'),
(1, 'APP-SRV-03', 'servidor', 'HP', 'ProLiant DL380', 'SN-HP-001', 6, 2, '10.10.1.13', 'manutencao', 'Em manutenção — HD com falha'),
(1, 'PATCH-A01-01', 'patch_panel', 'AMP', 'Cat6 24P', 'SN-AMP-001', 40, 1, '', 'ativo', 'Patch panel estruturado'),
(1, 'PDU-A01-01', 'pdu', 'APC', 'AP8853', 'SN-APC-001', 42, 1, '10.10.1.20', 'ativo', 'PDU gerenciável 0U'),
-- RACK-A02 (id=2)
(2, 'DB-SRV-01', 'servidor', 'Dell', 'PowerEdge R940', 'SN-DELL-010', 2, 4, '10.10.2.11', 'ativo', 'Servidor MySQL primário'),
(2, 'DB-SRV-02', 'servidor', 'Dell', 'PowerEdge R940', 'SN-DELL-011', 6, 4, '10.10.2.12', 'ativo', 'Servidor MySQL réplica'),
-- RACK-B01 (id=3)
(3, 'CORE-SW-01', 'switch', 'Cisco', 'Catalyst 9300-48P', 'SN-CSC-001', 1, 1, '10.10.3.1', 'ativo', 'Switch core camada 3'),
(3, 'CORE-SW-02', 'switch', 'Cisco', 'Catalyst 9300-48P', 'SN-CSC-002', 2, 1, '10.10.3.2', 'ativo', 'Switch core redundante'),
(3, 'FW-01', 'firewall', 'Fortinet','FortiGate 200F', 'SN-FTN-001', 4, 1, '10.10.3.10', 'ativo', 'Firewall principal'),
-- RACK-B02 (id=4)
(4, 'SAN-STOR-01', 'storage', 'NetApp', 'FAS2750', 'SN-NTA-001', 2, 4, '10.10.4.11', 'ativo', 'Storage SAN principal'),
(4, 'BACKUP-SRV-01','servidor', 'HP', 'ProLiant DL360', 'SN-HP-010', 8, 2, '10.10.4.20', 'ativo', 'Servidor de backup Veeam');
INSERT INTO cabos (origem_ativo_id, origem_porta, destino_ativo_id, destino_porta, tipo_cabo, comprimento_m, cor) VALUES
(1, 'eth0', 8, 'Gi0/1', 'ethernet_cat6', 2.00, 'azul'),
(2, 'eth0', 8, 'Gi0/2', 'ethernet_cat6', 2.00, 'azul'),
(6, 'eth0', 9, 'Gi0/1', 'ethernet_cat6', 3.00, 'verde'),
(8, 'uplink1', 10, 'port1', 'fibra_om3', 10.00, 'laranja');