--ABS-79069/ABS-79216

---------------- CONTRACT ----------------
ALTER TABLE CONTRACT ADD (QUANTITYMANAGEMENT VARCHAR2(1) DEFAULT 'N' NOT NULL
                          CONSTRAINT YN_VALIDATIONFIELD472 CHECK(QUANTITYMANAGEMENT IN('Y','N')));
                         
---------------- CONTRACTQMGROUP ----------------
CREATE SEQUENCE SEQ_CONTRACTQMGROUP START WITH 1 INCREMENT BY 1;

CREATE TABLE CONTRACTQMGROUP(
CONTRACTQMGROUP_ID NUMBER NOT NULL,
CONTRACT_ID NUMBER NOT NULL,
CODE VARCHAR2(15) NOT NULL,
DESCRIPTION VARCHAR2(50) NOT NULL,
SYSTEMUSER_ID NUMBER NOT NULL,
TIMESTAMP DATE NOT NULL);

ALTER TABLE CONTRACTQMGROUP
ADD CONSTRAINT XPKCONTRACTQMGROUP PRIMARY KEY(CONTRACTQMGROUP_ID);

CREATE UNIQUE INDEX XAK1CONTRACTQMGROUP ON CONTRACTQMGROUP(CONTRACT_ID ASC, CODE ASC);

ALTER TABLE CONTRACTQMGROUP ADD CONSTRAINT CONTRACTQMGROUP_CONTRACT FOREIGN KEY(CONTRACT_ID)
REFERENCES CONTRACT(CONTRACT_ID) ON DELETE CASCADE;

---------------- CONTRACTCUSTOMERQMGROUP ----------------
CREATE TABLE CONTRACTCUSTOMERQMGROUP(
CONTRACTCUSTOMER_ID NUMBER NOT NULL,
CONTRACTQMGROUP_ID NUMBER NOT NULL,
SYSTEMUSER_ID NUMBER NOT NULL,
TIMESTAMP DATE NOT NULL);

ALTER TABLE CONTRACTCUSTOMERQMGROUP 
ADD CONSTRAINT XPKCONTRACTCUSTOMERQMGROUP PRIMARY KEY(CONTRACTCUSTOMER_ID);

CREATE INDEX XIF1CONTRACTCUSTOMERQMGROUP ON CONTRACTCUSTOMERQMGROUP(CONTRACTQMGROUP_ID ASC);

ALTER TABLE CONTRACTCUSTOMERQMGROUP ADD CONSTRAINT CCQMGROUP_CONTRACTQMGROUP FOREIGN KEY(CONTRACTQMGROUP_ID)
REFERENCES CONTRACTQMGROUP(CONTRACTQMGROUP_ID);