@@ -5821,18 +5821,22 @@ CREATE TABLE IF NOT EXISTS omicron.public.audit_log (
58215821 OR (time_completed IS NOT NULL AND result_kind IS NOT NULL )
58225822 ),
58235823
5824- -- make sure we always have a status code for success and error results.
5825- -- in other words, the only times http_status_code is allowed to be null is
5826- -- when either there is no result yet or the result is a timeout
5827- CONSTRAINT status_code_present_for_success_error CHECK (
5828- result_kind = ' timeout'
5829- OR result_kind IS NULL
5830- OR http_status_code IS NOT NULL
5831- ),
5832-
5833- -- when result_kind is error, we always have an error message
5834- CONSTRAINT message_present_for_error CHECK (
5835- result_kind != ' error' OR error_message IS NOT NULL
5824+ -- Enforce consistency between result_kind and related fields:
5825+ -- 'timeout': no HTTP status or error details
5826+ -- 'success': requires HTTP status, no error details
5827+ -- 'error': requires HTTP status and error message
5828+ -- other/NULL: no HTTP status or error details
5829+ CONSTRAINT result_kind_state_consistency CHECK (
5830+ CASE result_kind
5831+ WHEN ' timeout' THEN http_status_code IS NULL AND error_code IS NULL
5832+ AND error_message IS NULL
5833+ WHEN ' success' THEN error_code IS NULL AND error_message IS NULL AND
5834+ http_status_code IS NOT NULL
5835+ WHEN ' error' THEN http_status_code IS NOT NULL AND error_message IS
5836+ NOT NULL
5837+ ELSE http_status_code IS NULL AND error_code IS NULL AND error_message
5838+ IS NULL
5839+ END
58365840 ),
58375841
58385842 -- Ensure valid actor ID combinations
0 commit comments