CREATE TABLE community_deletion_checkpoints ( request_id UUID NOT NULL REFERENCES community_deletion_requests(id) ON DELETE RESTRICT, sequence BIGINT GENERATED ALWAYS AS IDENTITY, stage TEXT NOT NULL, unit_key TEXT NOT NULL, status TEXT NOT NULL CHECK (status IN ('started', 'completed', 'failed')), lease_generation BIGINT NOT NULL CHECK (lease_generation > 0), attempts INTEGER NOT NULL DEFAULT 1 CHECK (attempts > 0), detail JSONB NOT NULL DEFAULT '{}'::jsonb, error TEXT, started_at TIMESTAMPTZ NOT NULL DEFAULT now(), completed_at TIMESTAMPTZ, PRIMARY KEY (request_id, sequence), UNIQUE (request_id, stage, unit_key), CHECK ((status = 'completed') = (completed_at IS NOT NULL)), CHECK ((status = 'failed') = (error IS NOT NULL)) );