﻿--drop unique constraints (novas serão criadas pela BC 3.63.0). Rodar antes da atualização ou, caso execute depois, necessário reiniciar a BC ou reaplicar a atu
DO $body$
DECLARE r record;
BEGIN
    FOR r IN select tc.table_schema, tc.table_name, tc.constraint_name
		from information_schema.table_constraints tc
		where tc.table_schema = 'cmb_standard' 
		and tc.table_name in ('portal_cotacao_frete_transp', 'portal_ordem_transporte', 'portal_cota_transportadora') 
		and tc.constraint_type = 'UNIQUE'
    LOOP
       EXECUTE 'ALTER TABLE ' || quote_ident(r.table_schema)||'.'||quote_ident(r.table_name) || ' DROP CONSTRAINT '|| quote_ident(r.constraint_name) || ';';
    END LOOP;
END
$body$;
--preencher campo st_digital de registros antigos, rodar após a atualização 
update cmb_standard.portal_cotacao_frete_transp set st_digital = true 
 where st_digital is null and transportador_id in (select clifor_id from cmb_standard.portal_configuracao_transp_digital);
update cmb_standard.portal_ordem_transporte set st_digital = true 
 where st_digital is null and transportador_id in (select clifor_id from cmb_standard.portal_configuracao_transp_digital);
update cmb_standard.portal_cota_transportadora set st_digital = true 
 where st_digital is null and transportadora_id in (select clifor_id from cmb_standard.portal_configuracao_transp_digital);
update cmb_standard.portal_cotacao_frete_transp set st_digital = false 
 where st_digital is null and transportador_id not in (select clifor_id from cmb_standard.portal_configuracao_transp_digital);
update cmb_standard.portal_ordem_transporte set st_digital = false
 where st_digital is null and transportador_id not in (select clifor_id from cmb_standard.portal_configuracao_transp_digital);
update cmb_standard.portal_cota_transportadora set st_digital = false 
 where st_digital is null and transportadora_id not in (select clifor_id from cmb_standard.portal_configuracao_transp_digital);