mirror of
https://github.com/block/buzz.git
synced 2026-10-27 12:40:30 +00:00
refactor(schema): fan desired-state schema out to one file per table (#8131)
This commit is contained in:
24
schema/functions/community_write_allowed.sql
Normal file
24
schema/functions/community_write_allowed.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Fleet-wide writers filter candidates through this VOLATILE predicate in
|
||||
-- the mutating statement so fenced tenants are skipped before row triggers run.
|
||||
CREATE FUNCTION community_write_allowed(target UUID) RETURNS BOOLEAN
|
||||
LANGUAGE plpgsql VOLATILE AS $$
|
||||
DECLARE
|
||||
lifecycle TEXT;
|
||||
BEGIN
|
||||
IF current_setting('transaction_isolation') <> 'read committed' THEN
|
||||
RAISE EXCEPTION 'community writes require READ COMMITTED isolation'
|
||||
USING ERRCODE = 'invalid_transaction_state';
|
||||
END IF;
|
||||
|
||||
IF target IS NULL THEN
|
||||
RETURN true;
|
||||
END IF;
|
||||
|
||||
PERFORM pg_advisory_xact_lock_shared(community_deletion_lock_key(target));
|
||||
SELECT deletion_state
|
||||
INTO lifecycle
|
||||
FROM communities
|
||||
WHERE id = target;
|
||||
RETURN FOUND AND lifecycle = 'active';
|
||||
END
|
||||
$$;
|
||||
Reference in New Issue
Block a user