ALTER TABLE tasks
  ADD COLUMN zip_build_token UUID,
  ADD COLUMN zip_build_lease_until TIMESTAMPTZ,
  ADD COLUMN zip_build_attempt BIGINT NOT NULL DEFAULT 0;

ALTER TABLE tasks
  ADD CONSTRAINT tasks_zip_build_lease_pair_check
  CHECK ((zip_build_token IS NULL) = (zip_build_lease_until IS NULL));

CREATE INDEX idx_tasks_zip_build_lease
  ON tasks(zip_build_lease_until)
  WHERE zip_storage_key IS NULL AND zip_build_token IS NOT NULL;
