Files
rust-ipam/seeds/postgres/dev_seed.sql
mathieu d9ee121fbb feat(networks): add name field to networks
- Migration 0007: ALTER TABLE networks ADD COLUMN name TEXT NOT NULL DEFAULT ''
- Network model, repository, and API updated to include name
- Networks page: name input in the add form, Name column as first column in table
- Delete modal now shows "Name (CIDR)" for clarity
- Hosts page: network dropdowns now show network name instead of CIDR
- Seeds updated with names (LAN, DMZ, Corporate, VPN)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 01:38:40 +02:00

63 lines
2.5 KiB
SQL

-- dev_seed.sql (PostgreSQL) — development test data
--
-- Running this script is idempotent: existing rows are left untouched
-- and missing rows are inserted. Safe to run multiple times.
--
-- Load with: cargo run --features ssr --bin seed
-- ── Networks ──────────────────────────────────────────────────────────────────
INSERT INTO networks (name, cidr) VALUES
('LAN', '192.168.1.0/24'),
('DMZ', '192.168.10.0/24'),
('Corporate', '10.0.0.0/8'),
('VPN', '172.16.0.0/16')
ON CONFLICT (cidr) DO NOTHING;
-- ── Hosts ─────────────────────────────────────────────────────────────────────
-- LAN — 192.168.1.0/24
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '192.168.1.0/24')
FROM (VALUES
('gateway', '192.168.1.1'),
('workstation-01', '192.168.1.10'),
('workstation-02', '192.168.1.11'),
('workstation-03', '192.168.1.12'),
('nas-01', '192.168.1.20'),
('printer-01', '192.168.1.50')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);
-- DMZ — 192.168.10.0/24
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '192.168.10.0/24')
FROM (VALUES
('web-server-01', '192.168.10.10'),
('web-server-02', '192.168.10.11'),
('db-server-01', '192.168.10.20'),
('mail-server-01', '192.168.10.30')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);
-- Corporate backbone — 10.0.0.0/8
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '10.0.0.0/8')
FROM (VALUES
('core-switch-01', '10.0.0.1'),
('monitoring-01', '10.0.1.10'),
('backup-server-01', '10.0.1.20'),
('log-server-01', '10.0.1.30')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);
-- VPN — 172.16.0.0/16
INSERT INTO hosts (name, ip, network_id)
SELECT name, ip, (SELECT id FROM networks WHERE cidr = '172.16.0.0/16')
FROM (VALUES
('vpn-gateway-01', '172.16.0.1'),
('vpn-client-01', '172.16.1.10'),
('vpn-client-02', '172.16.1.11')
) AS t(name, ip)
WHERE NOT EXISTS (SELECT 1 FROM hosts WHERE hosts.name = t.name AND hosts.ip = t.ip);