-- add columns contact.allow_record and permissions.allow_record
BEGIN;

CREATE or REPLACE FUNCTION  add_allow_record() RETURNS integer AS '
  BEGIN
    IF SPLIT_PART(VERSION(), '' '', 2) = ''7.4.7''
    THEN
      alter table contact add column allow_record varchar(3);
      update contact set allow_record = ''no'' where allow_record is null;
      alter table contact alter allow_record set default ''no'';
      alter table contact alter allow_record set not null;

      alter table permissions add column allow_record varchar(3);
      update permissions set allow_record = ''no'' where allow_record is null;
      alter table permissions alter allow_record set default ''no'';
      alter table permissions alter allow_record set not null;
    ELSE
      alter table contact add column allow_record varchar(3) not null default ''no'';
      alter table permissions add column allow_record varchar(3) not null default ''no'';
    END IF;
    RETURN 0;
  END;
' LANGUAGE plpgsql;

select add_allow_record(); 
      
DROP FUNCTION add_allow_record();
COMMIT;


