-- Migration from 005 to 006

ALTER TABLE CHANNELS ADD COLUMN CODE NAME;
ALTER TABLE CHANNELS DROP CONSTRAINT CHANNELS_UK_1;
ALTER TABLE CHANNELS DROP CONSTRAINT CHANNELS_UK_2;
UPDATE CHANNELS SET CODE = regexp_replace(upper(NAME), '[^A-Z0-9]', '_', 'g');
ALTER TABLE CHANNELS RENAME COLUMN NAME TO LABEL;
ALTER TABLE CHANNELS ALTER COLUMN CODE SET NOT NULL;
ALTER TABLE CHANNELS ADD CONSTRAINT CHANNELS_UK_1 UNIQUE(CODE, DS_ID);
ALTER TABLE CHANNELS ADD CONSTRAINT CHANNELS_UK_2 UNIQUE(CODE, EXP_ID);

ALTER TABLE FEATURE_DEFS ADD COLUMN CODE NAME;
ALTER TABLE FEATURE_DEFS DROP CONSTRAINT FEATURE_DEFS_UK_1;
UPDATE FEATURE_DEFS SET CODE = regexp_replace(upper(NAME), '[^A-Z0-9]', '_', 'g');
ALTER TABLE FEATURE_DEFS RENAME COLUMN NAME TO LABEL;
ALTER TABLE FEATURE_DEFS ALTER COLUMN CODE SET NOT NULL;
ALTER TABLE FEATURE_DEFS ADD CONSTRAINT FEATURE_DEFS_UK_1 UNIQUE(CODE, DS_ID);
