-- ABS-83744 / ABS-84796

-------------- CONTACT --------------

ALTER TABLE CONTACT ADD (ORIGINALCONTACT_ID NUMBER NULL);

CREATE INDEX XIF16CONTACT ON CONTACT(ORIGINALCONTACT_ID ASC);

ALTER TABLE CONTACT ADD CONSTRAINT FK_CONTACT_ORIGINALCONTACT_ID 
FOREIGN KEY(ORIGINALCONTACT_ID)
REFERENCES CONTACT(CONTACT_ID);

COMMENT ON COLUMN CONTACT.ORIGINALCONTACT_ID
IS 'Optional, so may be left empty. Default null.
Will only be filled when created automatically as a result of a mass creation';

ALTER INDEX XIF12CONTACTFOLLOWUPNOTE
RENAME TO XIF12CONTACT;
ALTER INDEX XIF13CONTACTFOLLOWUPNOTE
RENAME TO XIF13CONTACT;
ALTER INDEX XIF14CONTACTFOLLOWUPNOTE
RENAME TO XIF14CONTACT;
ALTER INDEX XIF15CONTACTFOLLOWUPNOTE
RENAME TO XIF15CONTACT;

------------------------- USERGROUP ------------------

ALTER TABLE USERGROUP DROP CONSTRAINT CHK_USERGROUP_ALLOWCONTMGRDMAP;
ALTER TABLE USERGROUP DROP CONSTRAINT CHK_USERGROUP_ALLOWCONTMGRCOMP;

ALTER TABLE USERGROUP RENAME COLUMN ALLOWCONTACTMGRDMAPPROVAL TO ALLOWCONTACTMGRREVIEW;
ALTER TABLE USERGROUP RENAME COLUMN ALLOWCONTACTMGRCOMPLETION TO ALLOWCONTACTMGRCLOSE;

ALTER TABLE USERGROUP ADD CONSTRAINT CHK_USERGROUP_ALLOWCONTMGRREV CHECK (ALLOWCONTACTMGRREVIEW IN('Y','N'));
ALTER TABLE USERGROUP ADD CONSTRAINT CHK_USERGROUP_ALLOWCONTMGRCLOS CHECK (ALLOWCONTACTMGRCLOSE IN('Y','N'));