--ABS-7395 / ABS-9605

ALTER TABLE WEIGHINGCATEGPERCUSTOMER ADD (CUSTOMERBUDGETDEFINITION_ID NUMBER NULL);
 
CREATE INDEX XIF5WEIGHINGCATEGPERCUSTOMER ON WEIGHINGCATEGPERCUSTOMER (CUSTOMERBUDGETDEFINITION_ID);

ALTER TABLE WEIGHINGCATEGPERCUSTOMER
  ADD CONSTRAINT WGHCATCUST_CUSTOMERBUDGETDEF FOREIGN KEY (CUSTOMERBUDGETDEFINITION_ID)
  REFERENCES CUSTOMERBUDGETDEFINITION (CUSTOMERBUDGETDEFINITION_ID) ON DELETE SET NULL;


CREATE SEQUENCE SEQ_CUSTOMERBUDGETINVLINETYPE
START WITH 1
INCREMENT BY 1;

CREATE TABLE CUSTOMERBUDGETINVLINETYPE
(
  CUSTOMERBUDGETINVLINETYPE_ID NUMBER NOT NULL,
  CUSTOMERBUDGETDEFINITION_ID NUMBER NOT NULL,
  INVOICELINETYPE_ID          NUMBER NOT NULL,
  SYSTEMUSER_ID               NUMBER NOT NULL,
  TIMESTAMP                   DATE NOT NULL
)
;

CREATE INDEX XIF1CUSTOMERBUDGETINVLINETYPE ON CUSTOMERBUDGETINVLINETYPE (CUSTOMERBUDGETDEFINITION_ID);
CREATE INDEX XIF2CUSTOMERBUDGETINVLINETYPE ON CUSTOMERBUDGETINVLINETYPE (INVOICELINETYPE_ID);
CREATE UNIQUE INDEX XAK1CUSTOMERBUDGETINVLINETYPE ON CUSTOMERBUDGETINVLINETYPE (CUSTOMERBUDGETDEFINITION_ID, INVOICELINETYPE_ID);

ALTER TABLE CUSTOMERBUDGETINVLINETYPE
  ADD CONSTRAINT CUSTBUDGETINVLINETYPE_CUSTBDGT FOREIGN KEY (CUSTOMERBUDGETDEFINITION_ID)
  REFERENCES CUSTOMERBUDGETDEFINITION (CUSTOMERBUDGETDEFINITION_ID);
  
ALTER TABLE CUSTOMERBUDGETINVLINETYPE
  ADD CONSTRAINT CUSTBUDGETINVLINETYPE_INVLINET FOREIGN KEY (INVOICELINETYPE_ID)
  REFERENCES INVOICELINETYPE (INVOICELINETYPE_ID);
  
ALTER TABLE CUSTOMERBUDGETINVLINETYPE
  ADD CONSTRAINT XPKCUSTOMERBUDGETINVLINETYPE PRIMARY KEY (CUSTOMERBUDGETINVLINETYPE_ID);