Last active
September 20, 2020 01:34
-
-
Save jonathanalves/785850c5d3fba01620fdd54c1ad8c7e1 to your computer and use it in GitHub Desktop.
Querys asgard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO public.usuario | |
(id, cadastro, ativo, nome, administrador, alerta_certidao, atendente, digitalizador, financeiro, gestor, login, painel_atendimento, sangria, senha, valor_caixa, departamento_id) | |
VALUES(uuid_generate_v4(), CURRENT_TIMESTAMP, true, 'johnny', true, true, true, true, true, true, 'johnny', true, 0, '$2a$10$N1RmIRN4CNwuY7EIfTQhJOnJzFRmNSoa.maqWe2i3fFb6h2I2td8G', 0, 'b8e62c98-f28c-4af7-9620-90696aab89c6'); | |
-- após criação do schema public, antes dos backups, rodar: | |
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | |
CREATE EXTENSION IF NOT EXISTS "unaccent"; | |
CREATE EXTENSION IF NOT EXISTS "pg_trgm"; | |
/* CRIAR FUNCAO IMMUTABLE DO UNACCENT PARA OS INDICES */ | |
CREATE OR REPLACE FUNCTION f_unaccent(text) RETURNS text AS $func$ | |
SELECT unaccent('unaccent', $1) $func$ LANGUAGE sql IMMUTABLE SET search_path = public, pg_temp; | |
-- senha 123456 | |
update usuario set senha = '$2a$10$bQ8ikWXwqR5Wquy37juU1OeVZ2d/cE6FyreeVPS0u2Wz9NmnAcNxq'; | |
'$2a$10$mfCYLhJ445nlZC0L/.zsXe4t/qqO2VWB/rPgF1..ConltH4AvtTX2' | |
-- setar atribuicoes | |
truncate table atribuicao cascade ; | |
insert into atribuicao (id, etapa_id, tipo_servico_id, usuario_id) | |
select uuid_generate_v4(), e.id, n.id, u.id | |
from usuario u, tipo_servico n, etapa e | |
where e.dominio = n.dominio; | |
insert into atribuicao (id, etapa_id, natureza_id, usuario_id) | |
select uuid_generate_v4(), e.id, n.id, u.id | |
from usuario u, natureza n, etapa e | |
where e.tipo_servico_id = n.tipo_servico_id; | |
-------------------------------------------- | |
--select id from indicador_real where codigo = 10; --c5df0553-612c-4a89-9d48-10fff92f3f9f | |
select id from indicador_pessoal_versao where documento is not null and nome is not null and tipo_pessoa = 'FISICA' limit 4; | |
INSERT INTO public.indicador_real_proprietario( | |
fracao, indicador_pessoal_versao_id, indicador_real_id) | |
VALUES (25, 'c5df0553-612c-4a89-9d48-1058497fff92', 'c5df0553-612c-4a89-9d48-10fff92f3f9f'); | |
INSERT INTO public.indicador_real_proprietario( | |
fracao, indicador_pessoal_versao_id, indicador_real_id) | |
VALUES (25, 'c5df0553-612c-4a89-9d48-1058502fff92', 'c5df0553-612c-4a89-9d48-10fff92f3f9f'); | |
INSERT INTO public.indicador_real_proprietario( | |
fracao, indicador_pessoal_versao_id, indicador_real_id) | |
VALUES (25, 'c5df0553-612c-4a89-9d48-1058503fff92', 'c5df0553-612c-4a89-9d48-10fff92f3f9f'); | |
INSERT INTO public.indicador_real_proprietario( | |
fracao, indicador_pessoal_versao_id, indicador_real_id) | |
VALUES (25, 'c5df0553-612c-4a89-9d48-1058504fff92', 'c5df0553-612c-4a89-9d48-10fff92f3f9f'); | |
---------------------------------------- | |
SET session_replication_role = 'replica'; | |
DO $$ | |
declare | |
linha record; | |
pos int; | |
begin | |
pos := 1; | |
FOR linha IN SELECT id from excluir limit 60000 offset 1000 loop | |
RAISE NOTICE 'deletando id = % - %',linha.id,pos; | |
pos := pos + 1; | |
EXECUTE 'DELETE FROM indicador_pessoal_versao where id = ''' || linha.id || ''''; | |
END LOOP; | |
END$$; | |
SET session_replication_role = default; | |
SHOW session_replication_role | |
DO $$ | |
declare | |
linha record; | |
pos int; | |
begin | |
pos := 1; | |
FOR linha IN SELECT * from migracao.envolvido_protocolo where interessado_id is not null loop | |
RAISE NOTICE 'atualizando protocolo = % - %',linha.protocolo,pos; | |
pos := pos + 1; | |
EXECUTE 'UPDATE protocolo SET interessado_id = ''' || linha.interessado_id || ''' where id = ''' || linha.protocolo || ''''; | |
END LOOP; | |
END$$; | |
with valores as ( | |
select ato_id, sum(total) t, sum(emolumentos) e from selo where ato_id is not null group by ato_id | |
) | |
update ato set valor = valores.t, emolumentos = valores.e from valores where id = valores.ato_id and registro is not null; | |
with valores as ( | |
select certidao_id, sum(total) t, sum(emolumentos) e from selo where certidao_id is not null group by certidao_id | |
) | |
update certidao set valor = valores.t, emolumentos = valores.e from valores where id = valores.certidao_id and registro is not null; | |
-------------------- | |
select * | |
from selo | |
left join certidao on certidao.id = selo.certidao_id and certidao.selado is null | |
left join ato on ato.id = selo.ato_id and ato.selado is null | |
where ato.id is not null or certidao.id is not null | |
and selo.utilizacao::date > '2020-04-20' |
update indicador_pessoal set tipo_pessoa = 'JURIDICA' where documento like '%/%';
update indicador_pessoal set tipo_pessoa = 'FISICA' where documento like '%.%' and documento not like '%/%';
update indicador_pessoal set tipo_pessoa = (case when character_length(documento) > 12 then 'JURIDICA' else 'FISICA' end) where tipo_pessoa is null and documento not like '%.%';
update indicador_pessoal set tipo_pessoa = (case when character_length(documento) > 15 then 'JURIDICA' else 'FISICA' end) where tipo_pessoa is null and documento like '%.%';
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update selo set certidao_id = null where certidao_id = '8e622783-8b1e-4bce-9429-1e9d8944e1a6';
update selo_pendente set certidao_id = null where certidao_id = '8e622783-8b1e-4bce-9429-1e9d8944e1a6';
update certidao set selado = null, registro = null where id = '8e622783-8b1e-4bce-9429-1e9d8944e1a6';