DROP VIEW ipconfig;

ALTER TABLE packet  
	ALTER COLUMN packet_name TYPE VARCHAR(6) NOT NULL;
ALTER TABLE packet  
	ALTER COLUMN hive_id DROP NOT NULL;

CREATE VIEW ipconfig AS	
    SELECT DISTINCT ON (theunion.ipv4) theunion.ipv4,
    	theunion.name,
    	theunion.alias,
    	theunion.hivename
    FROM ( SELECT h.hive_name AS hivename,
            ip.inet_addr AS ipv4,
            'eth0:'::text || p.packet_name::text AS alias,
            p.packet_name AS name,
            2 AS prio
           FROM inet_addr ip
             JOIN packet p ON p.cur_inet_addr_id = ip.inet_addr_id
             JOIN hive h ON h.hive_id = p.hive_id
        UNION
         SELECT h.hive_name AS hivename,
            ip.inet_addr AS ipv4,
            'eth0'::text AS alias,
            h.hive_name AS name,
            1 AS prio
           FROM inet_addr ip
             JOIN hive h ON h.inet_addr_id = ip.inet_addr_id
		ORDER BY 2, 5) theunion;