ALTER TABLE "translation_jobs"
ADD COLUMN "processing_lease_id" UUID,
ADD COLUMN "processing_lease_expires_at" TIMESTAMP(3),
ADD COLUMN "queue_lease_id" UUID,
ADD COLUMN "queue_lease_expires_at" TIMESTAMP(3),
ADD COLUMN "queued_at" TIMESTAMP(3);

UPDATE "translation_jobs"
SET "processing_lease_expires_at" = CURRENT_TIMESTAMP
WHERE "status" = 'processing';

CREATE INDEX "translation_jobs_status_processing_lease_expires_at_idx"
ON "translation_jobs"("status", "processing_lease_expires_at");

CREATE INDEX "translation_jobs_queued_at_queue_lease_expires_at_idx"
ON "translation_jobs"("queued_at", "queue_lease_expires_at");
