BEGIN;

-- First drop the existing constraints.
ALTER TABLE phoneline_forwarding DROP CONSTRAINT phoneline_forwarding_when_busy_check;
ALTER TABLE phoneline_forwarding DROP CONSTRAINT phoneline_forwarding_when_dnd_check;
ALTER TABLE phoneline_forwarding DROP CONSTRAINT phoneline_forwarding_when_loggedoff_check;
ALTER TABLE phoneline_forwarding DROP CONSTRAINT phoneline_forwarding_when_noanswer_check;
ALTER TABLE phoneline_forwarding DROP CONSTRAINT phoneline_forwarding_when_unconditional_check;
ALTER TABLE phoneline_forwarding DROP CONSTRAINT phoneline_forwarding_when_unreachable_check;

-- Then change existing table entries.
UPDATE phoneline_forwarding SET when_busy = 'busytone' WHERE when_busy = 'busy';
UPDATE phoneline_forwarding SET when_dnd = 'busytone' WHERE when_dnd = 'busy';
UPDATE phoneline_forwarding SET when_loggedoff = 'busytone' WHERE when_loggedoff = 'busy';
UPDATE phoneline_forwarding SET when_noanswer = 'busytone' WHERE when_noanswer = 'busy';
UPDATE phoneline_forwarding SET when_unconditional = 'busytone' WHERE when_unconditional = 'busy';
UPDATE phoneline_forwarding SET when_unreachable = 'busytone' WHERE when_unreachable = 'busy';

-- Finally add new constraints.
ALTER TABLE phoneline_forwarding ADD CONSTRAINT phoneline_forwarding_when_busy_check
  CHECK (when_busy IN ('voicemail','operator','forward','busytone','busysignal','refuse','mobile','ask','hunt'));
ALTER TABLE phoneline_forwarding ADD CONSTRAINT phoneline_forwarding_when_dnd_check
  CHECK (when_dnd IN ('voicemail','operator','forward','busytone','busysignal','refuse','mobile','ask','hunt'));
ALTER TABLE phoneline_forwarding ADD CONSTRAINT phoneline_forwarding_when_loggedoff_check
  CHECK (when_loggedoff IN ('voicemail','operator','forward','busytone','busysignal','refuse','mobile','ask','hunt'));
ALTER TABLE phoneline_forwarding ADD CONSTRAINT phoneline_forwarding_when_noanswer_check
  CHECK (when_noanswer IN ('voicemail','operator','forward','busytone','busysignal','refuse','mobile','ask','hunt'));
ALTER TABLE phoneline_forwarding ADD CONSTRAINT phoneline_forwarding_when_unconditional_check
  CHECK (when_unconditional IN ('ring','voicemail','operator','forward','busytone','busysignal','refuse','mobile','ask','hunt'));
ALTER TABLE phoneline_forwarding ADD CONSTRAINT phoneline_forwarding_when_unreachable_check
  CHECK (when_unreachable IN ('voicemail','operator','forward','busytone','busysignal','refuse','mobile','ask','hunt'));

COMMIT;
