ALTER TABLE "TelegramUser"
ADD COLUMN "verifiedPhoneNumber" TEXT;

UPDATE "TelegramUser"
SET "verifiedPhoneNumber" = "phoneNumber"
WHERE "personalDataConsentAt" IS NOT NULL
  AND "phoneNumber" IS NOT NULL;

CREATE INDEX "TelegramUser_verifiedPhoneNumber_idx"
ON "TelegramUser"("verifiedPhoneNumber");

ALTER TABLE "ChatMessage"
ADD COLUMN "managerTelegramMessageId" TEXT,
ADD COLUMN "crmRelayQueuedAt" TIMESTAMP(3),
ADD COLUMN "crmRelayMatchedAt" TIMESTAMP(3);

CREATE UNIQUE INDEX "ChatMessage_managerTelegramMessageId_key"
ON "ChatMessage"("managerTelegramMessageId");

CREATE INDEX "ChatMessage_crmRelayQueuedAt_crmRelayMatchedAt_idx"
ON "ChatMessage"("crmRelayQueuedAt", "crmRelayMatchedAt");
