-- ============================================================ -- Omika Diagnostic Center -- 008_diagnostics_clients.sql -- Tâche 19 : registre des clients autorisés (serveurs clients) de l'API centrale. -- ============================================================ -- IDEMPOTENT : CREATE TABLE IF NOT EXISTS + CREATE UNIQUE INDEX IF NOT EXISTS. -- AUCUN DROP, AUCUNE suppression, AUCUNE migration destructive. -- PostgreSQL 18 compatible. -- -- Une ligne = un SERVEUR CLIENT autorisé à transmettre ses diagnostics vers -- Omika.Diagnostics.Api (CodeClient métier, ex. BATIK.01). -- -- client_code : CodeClient métier autoritaire (unique, normalisé UPPER côté code). -- enabled : FALSE => le client ne peut plus envoyer (réponse 403). -- api_key_hash : hash SHA-256 (hex 64) de la clé d'accès. JAMAIS la clé en clair. -- key_prefix : préfixe d'affichage de la clé (ex. "omkdiag_"), NON secret, -- permet d'identifier la clé dans l'interface sans l'exposer. -- created_at_utc : création du client. -- key_created_at_utc : génération de la clé COURANTE (utile après régénération). -- last_seen_at_utc : dernière réception d'un lot accepté ; NULL si jamais. -- -- CHOIX DE TYPE : aligné sur diagnostic_event (TEXT, TIMESTAMPTZ). Aucun secret -- réversible stocké ; la clé n'existe que sous forme de hash SHA-256 (§29/§30). -- ============================================================ CREATE TABLE IF NOT EXISTS diagnostics_clients ( id BIGSERIAL PRIMARY KEY, client_code TEXT NOT NULL, enabled BOOLEAN NOT NULL DEFAULT TRUE, api_key_hash TEXT NOT NULL, key_prefix TEXT NOT NULL, created_at_utc TIMESTAMPTZ NOT NULL, key_created_at_utc TIMESTAMPTZ NOT NULL, last_seen_at_utc TIMESTAMPTZ ); -- Unicité par CodeClient (un seul client par code, §26). CREATE UNIQUE INDEX IF NOT EXISTS ux_diagnostics_clients_client_code ON diagnostics_clients (client_code);