-- ABS-56538/ ABS-65768

ALTER TABLE CLEANROOMBATCHPKBOXQTY ADD (SIZEDEFINITION_ID NUMBER NULL);

UPDATE CLEANROOMBATCHPKBOXQTY CBBQ SET CBBQ.SIZEDEFINITION_ID = (SELECT SD.SIZEDEFINITION_ID FROM SIZEDEFINITION SD WHERE SD.CODE = '*');
COMMIT;

ALTER TABLE CLEANROOMBATCHPKBOXQTY MODIFY (SIZEDEFINITION_ID NOT NULL);

DROP INDEX XAK1CLEANROOMBATCHPKBOXQTY;
CREATE UNIQUE INDEX XAK1CLEANROOMBATCHPKBOXQTY ON CLEANROOMBATCHPKBOXQTY (CLEANROOMBATCHPKBOX_ID ASC, PRODUCT_LINK_ID ASC, FINISHINGMETHOD_ID ASC, SIZEDEFINITION_ID ASC);

CREATE INDEX XIF5CLEANROOMBATCHPKBOXQTY ON CLEANROOMBATCHPKBOXQTY (SIZEDEFINITION_ID ASC);

ALTER TABLE CLEANROOMBATCHPKBOXQTY
  ADD CONSTRAINT CRBPKBOXQTY_SD FOREIGN KEY (SIZEDEFINITION_ID)
  REFERENCES SIZEDEFINITION (SIZEDEFINITION_ID);
