-- ABS-94640 / ABS-98534

-------------- PLANTDEPTPERCUSTACTDEPT ------------
ALTER TABLE PLANTDEPTPERCUSTACTDEPT DROP COLUMN PLANTDEPTPERCUSTACT_ID;
ALTER TABLE PLANTDEPTPERCUSTACTDEPT ADD (CUSTOMER_ID NUMBER NOT NULL,
                                         ACTIVITY_ID NUMBER NOT NULL,
                                         PROCESSBUSINESSUNIT_ID NUMBER NOT NULL,
                                         INTERNALPROCESSINGBU_ID NUMBER NOT NULL);

DROP INDEX XAK1PLANTDEPTPERCUSTACTDEPT;
CREATE UNIQUE INDEX XAK1PLANTDEPTPERCUSTACTDEPT ON PLANTDEPTPERCUSTACTDEPT (CUSTOMER_ID ASC, ACTIVITY_ID ASC, PROCESSBUSINESSUNIT_ID ASC, INTERNALPROCESSINGBU_ID ASC, DEPARTMENT_ID ASC);
                                         
CREATE INDEX XIF4PLANTDEPTPERCUSTACTDEPT ON PLANTDEPTPERCUSTACTDEPT (CUSTOMER_ID ASC);
CREATE INDEX XIF5PLANTDEPTPERCUSTACTDEPT ON PLANTDEPTPERCUSTACTDEPT (ACTIVITY_ID ASC);
CREATE INDEX XIF6PLANTDEPTPERCUSTACTDEPT ON PLANTDEPTPERCUSTACTDEPT (PROCESSBUSINESSUNIT_ID ASC); 
CREATE INDEX XIF7PLANTDEPTPERCUSTACTDEPT ON PLANTDEPTPERCUSTACTDEPT (INTERNALPROCESSINGBU_ID ASC);  
  
ALTER TABLE PLANTDEPTPERCUSTACTDEPT
  ADD CONSTRAINT FK_PLDEPPERCUSTACTDEP_CUSTID FOREIGN KEY (CUSTOMER_ID)
  REFERENCES CUSTOMER (CUSTOMER_ID) ON DELETE CASCADE;
  
ALTER TABLE PLANTDEPTPERCUSTACTDEPT
  ADD CONSTRAINT FK_PLDEPPERCUSTACTDEP_ACTIVID FOREIGN KEY (ACTIVITY_ID)
  REFERENCES ACTIVITY (ACTIVITY_ID) ON DELETE CASCADE;

ALTER TABLE PLANTDEPTPERCUSTACTDEPT
  ADD CONSTRAINT FK_PLDEPPERCUSTACTDEP_PROCBUID FOREIGN KEY (PROCESSBUSINESSUNIT_ID)
  REFERENCES BUSINESSUNIT(BUSINESSUNIT_ID) ON DELETE CASCADE;
  
ALTER TABLE PLANTDEPTPERCUSTACTDEPT
  ADD CONSTRAINT FK_PLDEPPERCUSTACTDEP_INTPRCBU FOREIGN KEY (INTERNALPROCESSINGBU_ID)
  REFERENCES BUSINESSUNIT(BUSINESSUNIT_ID) ON DELETE CASCADE;