ALTER TABLE "identity_verification_requests"
  ADD COLUMN "purpose" VARCHAR(120),
  ADD COLUMN "valid_until" TIMESTAMPTZ(3);

ALTER TABLE "identity_users"
  ADD COLUMN "registration_idempotency_key" VARCHAR(160);

CREATE UNIQUE INDEX "identity_users_registration_idempotency_key_key"
  ON "identity_users"("registration_idempotency_key");

UPDATE "identity_users"
SET "verification_level" = 'LEVEL_2',
    "level_three_verified_at" = NULL
WHERE "verification_level" = 'LEVEL_3';

CREATE INDEX "identity_verification_requests_user_id_kind_purpose_status_valid_until_idx"
  ON "identity_verification_requests"("user_id", "kind", "purpose", "status", "valid_until");
