@@ -5802,18 +5802,22 @@ CREATE TABLE IF NOT EXISTS omicron.public.audit_log (
58025802 OR (time_completed IS NOT NULL AND result_kind IS NOT NULL )
58035803 ),
58045804
5805- -- make sure we always have a status code for success and error results.
5806- -- in other words, the only times http_status_code is allowed to be null is
5807- -- when either there is no result yet or the result is a timeout
5808- CONSTRAINT status_code_present_for_success_error CHECK (
5809- result_kind = ' timeout'
5810- OR result_kind IS NULL
5811- OR http_status_code IS NOT NULL
5812- ),
5813-
5814- -- when result_kind is error, we always have an error message
5815- CONSTRAINT message_present_for_error CHECK (
5816- result_kind != ' error' OR error_message IS NOT NULL
5805+ -- Enforce consistency between result_kind and related fields:
5806+ -- 'timeout': no HTTP status or error details
5807+ -- 'success': requires HTTP status, no error details
5808+ -- 'error': requires HTTP status and error message
5809+ -- other/NULL: no HTTP status or error details
5810+ CONSTRAINT result_kind_state_consistency CHECK (
5811+ CASE result_kind
5812+ WHEN ' timeout' THEN http_status_code IS NULL AND error_code IS NULL
5813+ AND error_message IS NULL
5814+ WHEN ' success' THEN error_code IS NULL AND error_message IS NULL AND
5815+ http_status_code IS NOT NULL
5816+ WHEN ' error' THEN http_status_code IS NOT NULL AND error_message IS
5817+ NOT NULL
5818+ ELSE http_status_code IS NULL AND error_code IS NULL AND error_message
5819+ IS NULL
5820+ END
58175821 ),
58185822
58195823 -- Ensure valid actor ID combinations
0 commit comments