-- Migration from 021 to 022

ALTER TABLE IMAGE_ZOOM_LEVELS DROP CONSTRAINT FK_IMAGE_ZOOM_LEVELS_2;
ALTER TABLE IMAGE_ZOOM_LEVELS DROP COLUMN IMAGE_TRANSFORMATION_ID;

CREATE TABLE IMAGE_ZOOM_LEVEL_TRANSFORMATIONS (
	ID BIGSERIAL NOT NULL,
	
  ZOOM_LEVEL_ID TECH_ID NOT NULL,
  CHANNEL_ID TECH_ID NOT NULL,
  IMAGE_TRANSFORMATION_ID TECH_ID NOT NULL,
  
  PRIMARY KEY(ID),
  CONSTRAINT FK_IMAGE_ZOOM_LEVEL_TRANSFORMATIONS_1 FOREIGN KEY (ZOOM_LEVEL_ID) REFERENCES IMAGE_ZOOM_LEVELS (ID) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT FK_IMAGE_ZOOM_LEVEL_TRANSFORMATIONS_2 FOREIGN KEY (CHANNEL_ID) REFERENCES CHANNELS (ID) ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE INDEX IMAGE_ZOOM_LEVEL_TRANSFORMATIONS_ZLID_IDX ON IMAGE_ZOOM_LEVEL_TRANSFORMATIONS(ZOOM_LEVEL_ID);
