\set ON_ERROR_STOP on

\c nubarchiva
SET SCHEMA 'nuba00001';

/*
 *********************************************
 * source: nuba-commons.02.create_fk.sql
 *                                           *
 *      This is an auto generated file.      *
 *     !!!!! DO NOT EDIT DIRECTLY. !!!!!     *
 *                                           *
 *********************************************
 */

ALTER TABLE AUTHORITIES
	ADD CONSTRAINT AUTHORITIES_FK_USERS FOREIGN KEY (USERNAME) 
  	REFERENCES USERS(USERNAME);
/*
 *********************************************
 * source: nuba-opac.02.create_fk.sql
 *                                           *
 *      This is an auto generated file.      *
 *     !!!!! DO NOT EDIT DIRECTLY. !!!!!     *
 *                                           *
 *********************************************
 */

ALTER TABLE ITEM
    ADD CONSTRAINT ITEM_FK_ARCHIVE FOREIGN KEY (IDARCHIVE) 
    REFERENCES ARCHIVE(IDARCHIVE);
    
ALTER TABLE ITEM
    ADD CONSTRAINT ITEM_FK_ITEM FOREIGN KEY (IDPARENT) 
    REFERENCES ITEM(IDITEM);
    
ALTER TABLE ITEM
    ADD CONSTRAINT ITEM_FK_DESCLEVEL FOREIGN KEY (IDDESCRIPTIONLEVEL)
    REFERENCES DESCRIPTIONLEVEL(IDDESCRIPTIONLEVEL);

ALTER TABLE PLACERELATION
	ADD CONSTRAINT PLACERELA_FK_PLACE_A FOREIGN KEY (IDPLACEA) 
	REFERENCES PLACE(IDPLACE);
	
ALTER TABLE PLACERELATION
	ADD CONSTRAINT PLACERELA_FK_PLACE_B FOREIGN KEY (IDPLACEB) 
	REFERENCES PLACE(IDPLACE);

ALTER TABLE FIXEDTERM
    ADD CONSTRAINT FIXTERM_FK_FIX_SEARCH FOREIGN KEY (IDFIXEDSEARCH) 
    REFERENCES FIXEDSEARCH(IDFIXEDSEARCH);
    
ALTER TABLE FIXEDSEARCHCONDITION
    ADD CONSTRAINT FIX_SEARCH_CON_FK_FIX_SEARCH FOREIGN KEY (IDFIXEDSEARCH) 
    REFERENCES FIXEDSEARCH(IDFIXEDSEARCH);

ALTER TABLE MONOGRAPHPORTAL
    ADD CONSTRAINT MONPORTAL_FK_FIX_SEARCH FOREIGN KEY (IDFIXEDSEARCH)
    REFERENCES FIXEDSEARCH(IDFIXEDSEARCH);

ALTER TABLE ATTACHMENT
	ADD CONSTRAINT ATTACHMENT_FK_ITEM FOREIGN KEY (IDITEM)
	REFERENCES ITEM (IDITEM);

/*
 *********************************************
 * source: nuba-desar.02.create_fk.sql
 *                                           *
 *      This is an auto generated file.      *
 *     !!!!! DO NOT EDIT DIRECTLY. !!!!!     *
 *                                           *
 *********************************************
 */

ALTER TABLE USERLISTVALUE
  ADD CONSTRAINT USRLISTVALUE_FK_USRLIST 
      FOREIGN KEY (IDUSERLIST)
      REFERENCES USERLIST(IDUSERLIST);
       
ALTER TABLE FIELD
  ADD CONSTRAINT FIELDS_FK_FORM 
      FOREIGN KEY (IDFORM) 
      REFERENCES FORM(IDFORM);
      
ALTER TABLE FIELD
  ADD CONSTRAINT FIELDS_FK_CLASSEDITOR 
      FOREIGN KEY (IDCLASSEDITOR)
      REFERENCES CLASSEDITOR(IDCLASSEDITOR);

ALTER TABLE ITEMEDIT
  ADD CONSTRAINT ITEMEDIT_FK_ITEM 
      FOREIGN KEY (IDITEM)
      REFERENCES ITEM(IDITEM);
      
ALTER TABLE ITEMEDIT
  ADD CONSTRAINT ITEMEDIT_FK_FORM
      FOREIGN KEY (IDFORM)
      REFERENCES FORM(IDFORM);

/*
 *********************************************
 * source: nuba-requests.02.create_fk.sql
 *                                           *
 *      This is an auto generated file.      *
 *     !!!!! DO NOT EDIT DIRECTLY. !!!!!     *
 *                                           *
 *********************************************
 */

ALTER TABLE ITEMSREQUEST_ITEM 
	ADD CONSTRAINT FKITEMSREQUEST 
	FOREIGN KEY (ITEMSREQUEST_ID) REFERENCES ITEMSREQUEST(IDENTITY);
ALTER TABLE ITEMSREQUEST_ITEM 
	ADD CONSTRAINT FKITEMSREQUESTITEMS 
	FOREIGN KEY (IDITEM) REFERENCES ITEM(IDITEM);
ALTER TABLE ITEMBORROW 
	ADD CONSTRAINT FKITEMBORROWITEM 
	FOREIGN KEY (IDITEM) REFERENCES ITEM(IDITEM);
ALTER TABLE ITEMBORROW
    ADD CONSTRAINT FKITEMBORROWITEMSREQUEST
    FOREIGN KEY (IDITEMSREQUEST) REFERENCES ITEMSREQUEST(IDENTITY);
/*
 *********************************************
 * source: nuba-submissions.02.create_fk.sql
 *                                           *
 *      This is an auto generated file.      *
 *     !!!!! DO NOT EDIT DIRECTLY. !!!!!     *
 *                                           *
 *********************************************
 */

ALTER TABLE SUBMISSION_DETAIL 
  ADD CONSTRAINT FKSUBMISSIONDETAIL 
      FOREIGN KEY (IDSUBMISSION) 
      REFERENCES SUBMISSION(IDENTITY);

/*
 *********************************************
 * source: nuba-authorities.02.create_fk.sql
 *                                           *
 *      This is an auto generated file.      *
 *     !!!!! DO NOT EDIT DIRECTLY. !!!!!     *
 *                                           *
 *********************************************
 */

ALTER TABLE AUTHORITYRELATION
	ADD CONSTRAINT AUTH_FK_AUTHORITY_A FOREIGN KEY (IDAUTHORITYA) REFERENCES AUTHORITY(IDAUTHORITY);

ALTER TABLE AUTHORITYRELATION
	ADD CONSTRAINT AUTH_FK_AUTHORITY_B FOREIGN KEY (IDAUTHORITYB) REFERENCES AUTHORITY(IDAUTHORITY);
