-- add column phone.dnd
BEGIN;

CREATE or REPLACE FUNCTION  add_phone_dnd() RETURNS integer AS '
  BEGIN
    IF SPLIT_PART(VERSION(), '' '', 2) = ''7.4.7''
    THEN
      alter table phone add column dnd varchar(3);
      update phone set dnd = ''yes'' where dnd is null;
      alter table phone alter phone_dnd set default ''no'';
      alter table phone alter phone_dnd set not null;
    ELSE
      alter table phone add column dnd varchar(3) not null default ''no'';
    END IF;
    RETURN 0;
  END;
' LANGUAGE plpgsql;

select add_phone_dnd();

DROP FUNCTION add_phone_dnd();
COMMIT;

