Files
buzz/migrations/0033_push_message_kinds.sql
Tom Brow 7bdefdf7a6 fix(db): renumber push message migration
Signed-off-by: Tom Brow <tomb@block.xyz>
2026-08-21 21:18:15 -07:00

25 lines
954 B
PL/PgSQL

-- Dogfood push is deliberately message-only. Replace the trigger allowlist
-- additively so already-applied 0018/0023 migrations remain checksum-stable.
CREATE OR REPLACE FUNCTION enqueue_push_match_job() RETURNS trigger
LANGUAGE plpgsql AS $$
BEGIN
-- Keep this allowlist identical to the relay's validated NIP-PL descriptor.
IF NEW.kind IN (9, 40002, 45001, 45003) THEN
PERFORM pg_advisory_xact_lock_shared(
hashtextextended('buzz_push_gate:' || NEW.community_id::text, 0));
IF EXISTS (
SELECT 1 FROM push_leases
WHERE community_id = NEW.community_id
AND active
AND endpoint_enabled
AND expires_at > EXTRACT(EPOCH FROM now())::bigint
) THEN
INSERT INTO push_match_queue (community_id, event_id)
VALUES (NEW.community_id, NEW.id)
ON CONFLICT DO NOTHING;
END IF;
END IF;
RETURN NEW;
END
$$;