Files
Assistant/database/migrations/011_commit_notification_envelope.sql
m 6e0040fe89
CI / test (pull_request) Successful in 12s
CI / test (push) Successful in 10s
feat: add notification delivery foundation
2026-08-16 19:08:07 +03:00

23 lines
1.5 KiB
PL/PgSQL

BEGIN;
SET ROLE commit_role;
ALTER TABLE commit.authorized_action_envelopes ADD COLUMN IF NOT EXISTS notification_template_code TEXT NOT NULL DEFAULT '';
ALTER TABLE commit.authorized_action_envelopes ADD COLUMN IF NOT EXISTS capability_binding_id TEXT NOT NULL DEFAULT '';
ALTER TABLE commit.authorized_action_envelopes ADD COLUMN IF NOT EXISTS capability_binding_revision BIGINT NOT NULL DEFAULT 0;
ALTER TABLE commit.authorized_action_envelopes ADD COLUMN IF NOT EXISTS notification_title TEXT NOT NULL DEFAULT '';
ALTER TABLE commit.authorized_action_envelopes ADD COLUMN IF NOT EXISTS notification_message TEXT NOT NULL DEFAULT '';
ALTER TABLE commit.authorized_action_envelopes ADD COLUMN IF NOT EXISTS request_digest TEXT NOT NULL DEFAULT '';
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='authorized_action_notification_evidence_v1' AND conrelid='commit.authorized_action_envelopes'::regclass) THEN
ALTER TABLE commit.authorized_action_envelopes ADD CONSTRAINT authorized_action_notification_evidence_v1 CHECK (
operation <> 'deliver-prospective-notification-v1' OR (
notification_template_code = 'prospective-delivered-v1' AND notification_title <> '' AND notification_message <> '' AND
capability_binding_id <> '' AND capability_binding_revision > 0 AND
request_digest ~ '^[0-9a-f]{64}$' AND expected_prospective_revision > 0 AND prospective_item_id <> ''
)
) NOT VALID;
END IF;
END $$;
ALTER TABLE commit.authorized_action_envelopes VALIDATE CONSTRAINT authorized_action_notification_evidence_v1;
RESET ROLE;
COMMIT;