-- AlterTable
ALTER TABLE "Session" ADD COLUMN IF NOT EXISTS "refreshToken" TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN IF NOT EXISTS "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN IF NOT EXISTS "lastUsedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN IF NOT EXISTS "device" TEXT,
ADD COLUMN IF NOT EXISTS "ipAddress" TEXT,
ADD COLUMN IF NOT EXISTS "userAgent" TEXT,
ADD COLUMN IF NOT EXISTS "isActive" BOOLEAN NOT NULL DEFAULT true;

-- Make refreshToken unique after setting default value
ALTER TABLE "Session" ADD CONSTRAINT "Session_refreshToken_key" UNIQUE ("refreshToken");

-- Update existing refresh tokens to be unique
UPDATE "Session" SET "refreshToken" = id WHERE "refreshToken" = '';
