Files
buzz/schema/tables/public/community_serving_write_leases.sql
2026-11-19 17:51:45 -05:00

15 lines
651 B
SQL

CREATE TABLE community_serving_write_leases (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
community_id UUID NOT NULL,
operation TEXT NOT NULL,
owner TEXT NOT NULL,
generation BIGINT NOT NULL DEFAULT 1 CHECK (generation > 0),
-- Community fence generation observed when this lease was acquired.
fence_generation BIGINT NOT NULL CHECK (fence_generation >= 0),
lease_until TIMESTAMPTZ NOT NULL,
heartbeat_at TIMESTAMPTZ NOT NULL DEFAULT now(),
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX community_serving_write_leases_active
ON community_serving_write_leases (community_id, lease_until);