--ABS-50109/ ABS-50111

---WEARERACCOUNTABILITYHIST table---
CREATE SEQUENCE SEQ_WEARERACCOUNTABILITYHIST
START WITH 1
INCREMENT BY 1;

CREATE TABLE WEARERACCOUNTABILITYHIST
(
  WEARERACCOUNTABILITYHIST_ID NUMBER NOT NULL,
  WEARERINVENTORY_ID          NUMBER NOT NULL,
  DELIVERYDATE                DATE NOT NULL,
  QUANTITYIN                  NUMBER DEFAULT 0 NOT NULL,
  QUANTITYOUT                 NUMBER DEFAULT 0 NOT NULL,
  CUSTOMER_ID                 NUMBER NOT NULL,
  SYSTEMUSER_ID               NUMBER NOT NULL,
  TIMESTAMP                   DATE NOT NULL
)
;

ALTER TABLE WEARERACCOUNTABILITYHIST
  ADD CONSTRAINT XPKWEARERACCOUNTABILITYHIST PRIMARY KEY (WEARERACCOUNTABILITYHIST_ID);

CREATE UNIQUE INDEX XAK1WEARERACCOUNTABILITYHIST ON WEARERACCOUNTABILITYHIST (WEARERINVENTORY_ID ASC, DELIVERYDATE ASC);
CREATE INDEX XIF1WEARERACCOUNTABILITYHIST ON WEARERACCOUNTABILITYHIST (WEARERINVENTORY_ID ASC);
CREATE INDEX XIF2WEARERACCOUNTABILITYHIST ON WEARERACCOUNTABILITYHIST (CUSTOMER_ID ASC);
  
ALTER TABLE WEARERACCOUNTABILITYHIST
  ADD CONSTRAINT WEARERACCOUNTABILITYHIST_WI FOREIGN KEY (WEARERINVENTORY_ID)
  REFERENCES WEARERINVENTORY (WEARERINVENTORY_ID) ON DELETE CASCADE;
  
ALTER TABLE WEARERACCOUNTABILITYHIST
  ADD CONSTRAINT WEARERACCOUNTABILITYHIST_CUST FOREIGN KEY (CUSTOMER_ID)
  REFERENCES CUSTOMER (CUSTOMER_ID) ON DELETE CASCADE;