--- user_invites table
CREATE TABLE IF NOT EXISTS public.user_invites (
    id UUID DEFAULT gen_random_uuid () NOT NULL,
    email TEXT NOT NULL,
    token TEXT NOT NULL UNIQUE,
    expires_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now()
);

-- Primary Key
DO $$ 
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM pg_constraint 
        WHERE conname = 'user_invites_pkey' 
        AND conrelid = 'public.user_invites'::regclass
    ) THEN
        ALTER TABLE public.user_invites
        ADD CONSTRAINT user_invites_pkey PRIMARY KEY (id);
    END IF;
END $$;

CREATE INDEX IF NOT EXISTS idx_user_invites_token ON public.user_invites (token);