CREATE OR REPLACE VIEW pbx_ramais_mesa AS 
SELECT 0 AS tipo, pbx_sip_ramais.id, pbx_sip_ramais.nome, 
            pbx_sip_ramais.dispositivo, pbx_sip_ramais.callerid, 
            'SIP'::text AS tipo_table, pbx_sip_ramais.conta_senha, 
            ''::character varying AS ddd, pbx_sip_ramais.context AS contexto
           FROM pbx_sip_ramais
UNION ALL 
         SELECT 1 AS tipo, 0 AS id, pbx_ramais_agenda.rma_telefone AS nome, 
            pbx_ramais_agenda.rma_telefone AS dispositivo, 
            pbx_ramais_agenda.rma_nome AS callerid, 'AGD'::text AS tipo_table, 
            'F'::character varying AS conta_senha, pbx_ramais_agenda.ddd, 
            ' '::character varying AS contexto
           FROM pbx_ramais_agenda
UNION ALL 
	SELECT 0 AS tipo,id, nome, dispositivo, nome AS callerid,'IAX'::text AS tipo_table, 
	conta_senha, ''::character varying AS ddd, context AS contexto 
	FROM pbx_iax_pbx
ORDER BY callerid;

ALTER TABLE pbx_queues_grupos DROP COLUMN midiafila;
ALTER TABLE pbx_queues_grupos ADD COLUMN disponivelfila INT DEFAULT(1);