--Order 20013319.80
------------------------------PRODUCTCONVERSION---------------------------
ALTER TABLE PRODUCTCONVERSION ADD (DESTINATIONEMBLEMTEMPLATE_ID NUMBER NULL);

CREATE  INDEX XIF4PRODUCTCONVERSION ON PRODUCTCONVERSION
(DESTINATIONEMBLEMTEMPLATE_ID   ASC);

ALTER TABLE PRODUCTCONVERSION
ADD CONSTRAINT PRODUCTCONVERSION_EMBTEMP_ID FOREIGN KEY (DESTINATIONEMBLEMTEMPLATE_ID) REFERENCES EMBLEMTEMPLATE (EMBLEMTEMPLATE_ID);





------------------------------PRODUCTCONVWRINVENTORY---------------------------



CREATE SEQUENCE SEQ_PRODUCTCONVWRINVENTORY
START WITH 1
INCREMENT BY 1;

CREATE TABLE PRODUCTCONVWRINVENTORY
(
	PRODUCTCONVWRINVENTORY_ID           NUMBER NOT NULL ,
	PRODUCTCONVERSION_ID                      NUMBER NOT NULL ,
	WEARERINVENTORY_ID                        NUMBER NOT NULL ,
        DESTINATIONWISIZEDEFINITION_ID            NUMBER NOT NULL ,
        DESTINATIONWIEMBLEMTEMPLATE_ID            NUMBER NULL ,
	SYSTEMUSER_ID       			  NUMBER NOT NULL ,
	TIMESTAMP           			  DATE NOT NULL 
);


ALTER TABLE PRODUCTCONVWRINVENTORY
ADD CONSTRAINT  XPKPRODUCTCONVWRINVENTORY PRIMARY KEY (PRODUCTCONVWRINVENTORY_ID);

CREATE  INDEX XIF1PRODUCTCONVWRINVENTORY ON PRODUCTCONVWRINVENTORY
(PRODUCTCONVERSION_ID   ASC);

ALTER TABLE PRODUCTCONVWRINVENTORY
ADD CONSTRAINT PRODUCTCONVWRINV_PRODCONV_ID FOREIGN KEY (PRODUCTCONVERSION_ID) REFERENCES PRODUCTCONVERSION (PRODUCTCONVERSION_ID) ON DELETE CASCADE;

CREATE  INDEX XIF2PRODUCTCONVWRINVENTORY ON PRODUCTCONVWRINVENTORY
(WEARERINVENTORY_ID   ASC);

ALTER TABLE PRODUCTCONVWRINVENTORY
ADD CONSTRAINT PRODUCTCONVWRINV_WEARERINV_ID FOREIGN KEY (WEARERINVENTORY_ID) REFERENCES WEARERINVENTORY (WEARERINVENTORY_ID) ON DELETE CASCADE;

CREATE  INDEX XIF3PRODUCTCONVWRINVENTORY ON PRODUCTCONVWRINVENTORY
(DESTINATIONWISIZEDEFINITION_ID   ASC);

ALTER TABLE PRODUCTCONVWRINVENTORY
ADD CONSTRAINT PRODUCTCONVWRINV_SIZEDEF_ID FOREIGN KEY (DESTINATIONWISIZEDEFINITION_ID) REFERENCES SIZEDEFINITION (SIZEDEFINITION_ID) ON DELETE CASCADE;

CREATE  INDEX XIF4PRODUCTCONVWRINVENTORY ON PRODUCTCONVWRINVENTORY
(DESTINATIONWIEMBLEMTEMPLATE_ID  ASC);

ALTER TABLE PRODUCTCONVWRINVENTORY
ADD CONSTRAINT PRODUCTCONVWRINV_EMBTEMP_ID FOREIGN KEY (DESTINATIONWIEMBLEMTEMPLATE_ID) REFERENCES EMBLEMTEMPLATE (EMBLEMTEMPLATE_ID);

CREATE UNIQUE INDEX XAK1PRODUCTCONVWRINVENTORY ON PRODUCTCONVWRINVENTORY
(PRODUCTCONVERSION_ID   ASC, WEARERINVENTORY_ID ASC);




------------------------------PHASEOUTWEARERINVENTORY---------------------------



CREATE TABLE PHASEOUTWEARERINVENTORY
(
	PHASEOUTWEARERINVENTORY_ID              NUMBER NOT NULL ,
	PHASEINWEARERINVENTORY_ID               NUMBER NOT NULL ,
	SYSTEMUSER_ID       	                NUMBER NOT NULL ,
	TIMESTAMP           			DATE NOT NULL 
);

ALTER TABLE PHASEOUTWEARERINVENTORY
ADD CONSTRAINT  XPKPHASEOUTWEARERINVENTORY PRIMARY KEY (PHASEOUTWEARERINVENTORY_ID);

ALTER TABLE PHASEOUTWEARERINVENTORY
ADD CONSTRAINT PHASEOUTWEARERINV_WEARERINV1 FOREIGN KEY (PHASEOUTWEARERINVENTORY_ID) REFERENCES WEARERINVENTORY (WEARERINVENTORY_ID) ON DELETE CASCADE;

CREATE  INDEX XIF1PHASEOUTWEARERINVENTORY ON PHASEOUTWEARERINVENTORY
(PHASEINWEARERINVENTORY_ID  ASC);

ALTER TABLE PHASEOUTWEARERINVENTORY
ADD CONSTRAINT PHASEOUTWEARERINV_WEARERINV2 FOREIGN KEY (PHASEINWEARERINVENTORY_ID) REFERENCES WEARERINVENTORY (WEARERINVENTORY_ID) ON DELETE CASCADE;