CREATE TABLE public.notification( id_user integer NOT NULL, event text NOT NULL, target_id integer NOT NULL, CONSTRAINT notification_primary PRIMARY KEY (id_user, event, target_id) ); ALTER TABLE public.notification ADD CONSTRAINT id_user_fk FOREIGN KEY (id_user) REFERENCES public.user_info (id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE; CREATE INDEX notification_idx ON public.notification USING btree(event);