Repository Public
1-- Ingestion : idempotence des rapports, renouvellement de certificat sans coupure,2-- plafonds de sortie des commandes, re-calcul des agrégats pour les données tardives, observations NAS.34-- Un rapport (agent, seq) n'est appliqué qu'une fois. Les rapports tamponnés arrivent dans le désordre5-- par rapport aux rapports en direct : agents.last_seq (le plus grand vu) ne suffit donc pas à dédoublonner.6create table agent_report_seqs (7 agent_id uuid not null references agents(id),8 seq bigint not null,9 ts timestamptz not null, -- horodatage agent du rapport10 received_at timestamptz not null default now(),11 primary key (agent_id, seq)12);13create index on agent_report_seqs(received_at);1415-- Renouvellement : l'ancien certificat reste accepté un court délai, sinon une réponse perdue16-- enfermerait l'agent dehors (il n'aurait jamais reçu le nouveau certificat).17alter table agents18 add column prev_cert_serial text,19 add column prev_cert_valid_until timestamptz;20create index agents_prev_cert_serial on agents(prev_cert_serial) where prev_cert_serial is not null;2122-- Sortie d'une commande : bornée côté serveur (lignes / octets), marqueur de troncature écrit une seule fois.23alter table agent_commands24 add column output_lines int not null default 0,25 add column output_bytes int not null default 0,26 add column output_truncated boolean not null default false;2728-- Seaux d'agrégation à recalculer parce que des données tamponnées sont arrivées après le filigrane.29create table rollup_dirty (30 tier text not null check (tier in ('1m','1h')),31 bucket timestamptz not null,32 primary key (tier, bucket)33);3435-- Dernière observation de chaque NAS par chaque nœud ; nas_targets.state en est l'agrégat.36create table nas_observations (37 nas_id uuid not null references nas_targets(id) on delete cascade,38 node_id uuid not null references nodes(id),39 reachable boolean not null,40 mounted boolean not null,41 latency_ms real,42 total_bytes bigint,43 used_bytes bigint,44 observed_at timestamptz not null,45 primary key (nas_id, node_id)46);47