-- Add invite token columns to User table if they don't exist
-- These were accidentally skipped in the prototype1_improvements migration

DO $$
BEGIN
    -- Add inviteToken column if it doesn't exist
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name = 'User' AND column_name = 'inviteToken'
    ) THEN
        ALTER TABLE "User" ADD COLUMN "inviteToken" TEXT;
    END IF;

    -- Add inviteTokenExpiresAt column if it doesn't exist
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name = 'User' AND column_name = 'inviteTokenExpiresAt'
    ) THEN
        ALTER TABLE "User" ADD COLUMN "inviteTokenExpiresAt" TIMESTAMP(3);
    END IF;
END $$;

-- Create unique index on inviteToken if it doesn't exist
CREATE UNIQUE INDEX IF NOT EXISTS "User_inviteToken_key" ON "User"("inviteToken");
