   ORGANISATION_ID  INTEGER NOT NULL,
 
   PRIMARY KEY (USER_ID, FUNCTION_ID, ORGANISATION_ID),
-  CONSTRAINT FUNCTION_USER_MAP_USER_FK FOREIGN KEY (USER_ID) REFERENCES USERS(ID) ON DELETE CASCADE,
-  CONSTRAINT FUNCTION_USER_MAP_FUNCTION_FK FOREIGN KEY (FUNCTION_ID) REFERENCES FUNCTIONS(ID) ON DELETE CASCADE,
-  CONSTRAINT FUNCTION_USER_MAP_ORGANISATION_FK FOREIGN KEY (ORGANISATION_ID) REFERENCES ORGANISATIONS(ID) ON DELETE CASCADE
+  CONSTRAINT FUNCTION_USER_MAP_USER_FK FOREIGN KEY (USER_ID) REFERENCES MMP.USERS(ID) ON DELETE CASCADE,
+  CONSTRAINT FUNCTION_USER_MAP_FUNCTION_FK FOREIGN KEY (FUNCTION_ID) REFERENCES MMP.FUNCTIONS(ID) ON DELETE CASCADE,
+  CONSTRAINT FUNCTION_USER_MAP_ORGANISATION_FK FOREIGN KEY (ORGANISATION_ID) REFERENCES MMP.ORGANISATIONS(ID) ON DELETE CASCADE
 );
 
 CREATE INDEX FUNCTION_USER_MAP_USER_ID_IX

  TEMPLATE_ID  INTEGER NOT NULL,

  PRIMARY KEY (FUNCTION_ID, TEMPLATE_ID),
  CONSTRAINT FUNCTION_TEMPLATE_MAP_FUNC_FK FOREIGN KEY (FUNCTION_ID) REFERENCES FUNCTIONS(ID) ON DELETE CASCADE,
  CONSTRAINT FUNCTION_TEMPLATE_MAP_TMPL_FK FOREIGN KEY (TEMPLATE_ID) REFERENCES FUNCTION_TEMPLATES(ID) ON DELETE CASCADE
);

COMMENT ON COLUMN MMP.FUNCTION_TEMPLATE_MAP.FUNCTION_ID

COMMENT ON COLUMN MMP.CODES.VALUE
  IS 'The value for the code';

ALTER TABLE MMP.CODES ADD CONSTRAINT FK_CODES_CODE_CATEGORY FOREIGN KEY (CATEGORY_ID) REFERENCES MMP.CODE_CATEGORIES(ID) ON DELETE CASCADE;



