BEGIN;
alter table phone add column dtmfspeaker varchar(7);
update phone set dtmfspeaker = 'default' where dtmfspeaker IS NULL;
alter table phone alter column dtmfspeaker set NOT NULL;
alter table phone alter column dtmfspeaker set default 'default';
alter table phone add CONSTRAINT phone_dtmfspeaker_check CHECK (dtmfspeaker IN ('default', 'yes', 'no'));

alter table phonetype add column dtmfspeaker varchar(7);
update phonetype set dtmfspeaker = 'default' where dtmfspeaker IS NULL;
alter table phonetype alter column dtmfspeaker set NOT NULL;
alter table phonetype alter column dtmfspeaker set default 'default';
alter table phonetype add CONSTRAINT phone_dtmfspeaker_check CHECK (dtmfspeaker IN ('default', 'yes', 'no'));

alter table phonetypephone add column dtmfspeaker varchar(7);
update phonetypephone set dtmfspeaker = 'default' where dtmfspeaker IS NULL;
alter table phonetypephone alter column dtmfspeaker set NOT NULL;
alter table phonetypephone alter column dtmfspeaker set default 'default';
alter table phonetypephone add CONSTRAINT phone_dtmfspeaker_check CHECK (dtmfspeaker IN ('default', 'yes', 'no'));

alter table phonetypecontactphone add column dtmfspeaker varchar(7);
update phonetypecontactphone set dtmfspeaker = 'default' where dtmfspeaker IS NULL;
alter table phonetypecontactphone alter column dtmfspeaker set NOT NULL;
alter table phonetypecontactphone alter column dtmfspeaker set default 'default';
alter table phonetypecontactphone add CONSTRAINT phone_dtmfspeaker_check CHECK (dtmfspeaker IN ('default', 'yes', 'no'));

COMMIT;

BEGIN;
alter table phone add column tmp varchar(5);
update phone set tmp = 'pbx' where tmp IS NULL;
alter table phone alter column tmp set not null;
alter table phone alter column tmp set default 'pbx';
update phone set tmp = dndkeyfunc where dndkeyfunc IS NOT NULL;
update phone set tmp = '' where dndkeyfunc IS NULL;
alter table phone drop column dndkeyfunc;
alter table phone rename column tmp to dndkeyfunc;
alter table phone add constraint phone_dndkeyfunc_check CHECK (dndkeyfunc IN ('pbx', 'phone'));

alter table phonetype add column tmp varchar(5);
update phonetype set tmp = 'pbx' where tmp IS NULL;
alter table phonetype alter column tmp set not null;
alter table phonetype alter column tmp set default 'pbx';
update phonetype set tmp = dndkeyfunc where dndkeyfunc IS NOT NULL;
update phonetype set tmp = '' where dndkeyfunc IS NULL;
alter table phonetype drop column dndkeyfunc;
alter table phonetype rename column tmp to dndkeyfunc;
alter table phonetype add constraint phonetype_dndkeyfunc_check CHECK (dndkeyfunc IN ('pbx', 'phone'));

alter table phonetypephone add column tmp varchar(5);
update phonetypephone set tmp = 'pbx' where tmp IS NULL;
alter table phonetypephone alter column tmp set not null;
alter table phonetypephone alter column tmp set default 'pbx';
update phonetypephone set tmp = dndkeyfunc where dndkeyfunc IS NOT NULL;
update phonetypephone set tmp = '' where dndkeyfunc IS NULL;
alter table phonetypephone drop column dndkeyfunc;
alter table phonetypephone rename column tmp to dndkeyfunc;
alter table phonetypephone add constraint phonetypephone_dndkeyfunc_check CHECK (dndkeyfunc IN ('pbx', 'phone'));

alter table phonetypecontactphone add column tmp varchar(5);
update phonetypecontactphone set tmp = 'pbx' where tmp IS NULL;
alter table phonetypecontactphone alter column tmp set not null;
alter table phonetypecontactphone alter column tmp set default 'pbx';
update phonetypecontactphone set tmp = dndkeyfunc where dndkeyfunc IS NOT NULL;
update phonetypecontactphone set tmp = '' where dndkeyfunc IS NULL;
alter table phonetypecontactphone drop column dndkeyfunc;
alter table phonetypecontactphone rename column tmp to dndkeyfunc;
alter table phonetypecontactphone add constraint phonetypecontactphone_dndkeyfunc_check CHECK (dndkeyfunc IN ('pbx', 'phone'));

COMMIT;

