-- AlterTable
ALTER TABLE "user_accounts" ADD COLUMN "email" VARCHAR(100);

-- CreateIndex
CREATE UNIQUE INDEX "user_accounts_email_key" ON "user_accounts"("email");

-- CreateIndex
CREATE INDEX "idx_email" ON "user_accounts"("email");

-- CreateTable
CREATE TABLE "email_codes" (
    "id" BIGSERIAL NOT NULL,
    "email" VARCHAR(100) NOT NULL,
    "code" VARCHAR(10) NOT NULL,
    "purpose" VARCHAR(50) NOT NULL,
    "expires_at" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "used_at" TIMESTAMP(3),

    CONSTRAINT "email_codes_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "idx_email_purpose" ON "email_codes"("email", "purpose");

-- CreateIndex
CREATE INDEX "idx_email_expires" ON "email_codes"("expires_at");
