-- CreateEnum
CREATE TYPE "LoginStatus" AS ENUM ('Success', 'Failure');

-- CreateTable
CREATE TABLE "user_login_history" (
    "id" SERIAL NOT NULL,
    "userId" INTEGER NOT NULL,
    "loginAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "status" "LoginStatus" NOT NULL,
    "failureReason" TEXT,
    "ipAddress" TEXT,
    "userAgent" TEXT,

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

-- CreateIndex
CREATE INDEX "user_login_history_userId_idx" ON "user_login_history"("userId");

-- CreateIndex
CREATE INDEX "user_login_history_loginAt_idx" ON "user_login_history"("loginAt");

-- AddForeignKey
ALTER TABLE "user_login_history" ADD CONSTRAINT "user_login_history_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
