-- ABS-49299
------------------   LEGALENTITY   --------------------
ALTER TABLE LEGALENTITY DROP COLUMN CSINVOICEIMAGE;
ALTER TABLE LEGALENTITY DROP COLUMN CSDIRECTINVOICEIMAGE;
ALTER TABLE LEGALENTITY DROP COLUMN CSDELIVERYNOTEIMAGE;

ALTER TABLE LEGALENTITY ADD (CSINVOICEIMAGE_ID NUMBER NULL,
			     CSDIRECTINVOICEIMAGE_ID NUMBER NULL,
			     CSDELIVERYNOTEIMAGE_ID NUMBER NULL);

CREATE INDEX XIF7LEGALENTITY ON LEGALENTITY (CSINVOICEIMAGE_ID ASC);
CREATE INDEX XIF8LEGALENTITY ON LEGALENTITY (CSDIRECTINVOICEIMAGE_ID ASC);
CREATE INDEX XIF9LEGALENTITY ON LEGALENTITY (CSDELIVERYNOTEIMAGE_ID ASC);

ALTER TABLE LEGALENTITY ADD CONSTRAINT LEGALENTITY_INVIMGID FOREIGN KEY (CSINVOICEIMAGE_ID)
REFERENCES IMAGE (IMAGE_ID);

ALTER TABLE LEGALENTITY ADD CONSTRAINT LEGALENTITY_DIRINVIMGID FOREIGN KEY (CSDIRECTINVOICEIMAGE_ID)
REFERENCES IMAGE (IMAGE_ID);

ALTER TABLE LEGALENTITY ADD CONSTRAINT LEGALENTITY_DELNOTEIMGID FOREIGN KEY (CSDELIVERYNOTEIMAGE_ID)
REFERENCES IMAGE (IMAGE_ID);


------------------   IMAGE  --------------------
ALTER TABLE IMAGE DROP CONSTRAINT IMAGETYPE_VALID;

COMMENT ON COLUMN IMAGE.IMAGETYPE IS '1 = Product
2 = Placement
3 = Garment
4 = Unique Residential Item
5 = Company Stamp';

ALTER TABLE IMAGE ADD CONSTRAINT IMAGETYPE_VALID CHECK (IMAGETYPE IN (1,2,3,4,5));