-- add columns pcvlan_id and pcvlan_qos to network table.
BEGIN;

CREATE or REPLACE FUNCTION  add_pcvlan_columns() RETURNS integer AS '
  BEGIN
    IF SPLIT_PART(VERSION(), '' '', 2) = ''7.4.7''
    THEN
      alter table network add column pcvlan_id integer;
      update network set pcvlan_id = ''0'' where pcvlan_id is null;
      alter table network alter pcvlan_id set default ''0'';
      alter table network alter pcvlan_id set not null;

      alter table network add column pcvlan_qos integer;
      update network set pcvlan_qos = ''7'' where pcvlan_qos is null;
      alter table network alter pcvlan_qos set default ''7'';
      alter table network alter pcvlan_qos set not null;
    ELSE
      alter table network add column pcvlan_id integer not null default ''0'';
      alter table network add column pcvlan_qos integer not null default ''7'';
    END IF;
    RETURN 0;
  END;
' LANGUAGE plpgsql;

select add_pcvlan_columns(); 
      
DROP FUNCTION add_pcvlan_columns();
COMMIT;


