-- Add nullable columns first so existing jobs and outbox rows remain valid.
ALTER TABLE "translation_jobs"
    ADD COLUMN "submission_id" UUID,
    ADD COLUMN "submission_fingerprint" CHAR(64);

ALTER TABLE "webhook_outbox"
    ADD COLUMN "next_attempt_at" TIMESTAMP(3),
    ADD COLUMN "first_attempt_at" TIMESTAMP(3),
    ADD COLUMN "last_attempt_at" TIMESTAMP(3),
    ADD COLUMN "dead_at" TIMESTAMP(3),
    ADD COLUMN "response_status" INTEGER;

-- These indexes are built without a table-wide write lock by the migration lane.
CREATE UNIQUE INDEX CONCURRENTLY "translation_jobs_submission_id_key"
    ON "translation_jobs"("submission_id");

CREATE INDEX CONCURRENTLY "webhook_outbox_status_next_attempt_at_idx"
    ON "webhook_outbox"("status", "next_attempt_at");

CREATE INDEX CONCURRENTLY "webhook_outbox_status_claimed_at_idx"
    ON "webhook_outbox"("status", "claimed_at");
