Last active
July 2, 2021 14:58
-
-
Save jonathanalves/b69da2da2142b5b8fa98a8b48945070d to your computer and use it in GitHub Desktop.
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
delete from atribuicao where usuario_id in (select id from usuario where ativo is false); | |
delete from atribuicao where etapa_id in (select id from etapa where ativo is false); | |
delete from atribuicao where tipo_servico_id in (select id from tipo_servico where ativo is false); | |
delete from checklist_tipo_documento where tipo_documento_id in (select id from tipo_documento where ativo is false); | |
delete from checklist_tipo_documento where checklist_id in (select id from checklist where ativo is false); | |
delete from checklist_tipo_servico where tipo_servico_id in (select id from tipo_servico where ativo is false); | |
delete from checklist_tipo_servico where checklist_id in (select id from checklist where ativo is false); | |
delete from usuario_filas_atendimento where filas_atendimento_id in (select id from fila_atendimento where ativo is false); | |
delete from usuario_filas_atendimento where usuario_id in (select id from usuario where ativo is false); | |
delete from etapa_proxima where etapa_id in (select id from etapa where ativo is false); | |
delete from etapa_proxima where proxima_id in (select id from etapa where ativo is false); | |
delete from layout_impressao where ativo is false; | |
delete from fragmento where ativo is false; | |
delete from lista where ativo is false; | |
delete from modelo_textual where ativo is false; | |
delete from tipo_documento where ativo is false; | |
delete from repasse where ativo is false; | |
----- | |
DO $$ | |
DECLARE | |
pr usuario%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from usuario where ativo is false | |
LOOP | |
RAISE NOTICE 'trying to delete usuario id %',pr.id; | |
BEGIN | |
DELETE FROM usuario WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted product id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; | |
----- | |
DO $$ | |
DECLARE | |
pr natureza%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from natureza where ativo is false | |
LOOP | |
RAISE NOTICE 'trying to delete natureza id %',pr.id; | |
BEGIN | |
DELETE FROM natureza WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted natureza id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; | |
----- | |
DO $$ | |
DECLARE | |
pr tipo_servico%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from tipo_servico where ativo is false | |
LOOP | |
RAISE NOTICE 'trying to delete tipo_servico id %',pr.id; | |
BEGIN | |
DELETE FROM tipo_servico WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted tipo_servico id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; | |
----- | |
DO $$ | |
DECLARE | |
pr checklist%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from checklist where ativo is false | |
LOOP | |
RAISE NOTICE 'trying to delete checklist id %',pr.id; | |
BEGIN | |
DELETE FROM checklist WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted checklist id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; | |
----- | |
DO $$ | |
DECLARE | |
pr etapa%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from etapa where ativo is false | |
LOOP | |
RAISE NOTICE 'trying to delete etapa id %',pr.id; | |
BEGIN | |
DELETE FROM etapa WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted etapa id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; | |
----- | |
DO $$ | |
DECLARE | |
pr caixa%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from caixa where ativo is false | |
LOOP | |
RAISE NOTICE 'trying to delete caixa id %',pr.id; | |
BEGIN | |
DELETE FROM caixa WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted caixa id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; | |
----- | |
DO $$ | |
DECLARE | |
pr categoria%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from categoria where ativo is false order by categoria_id nulls last | |
LOOP | |
RAISE NOTICE 'trying to delete categoria id %',pr.id; | |
BEGIN | |
DELETE FROM categoria WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted categoria id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; | |
----- | |
DO $$ | |
DECLARE | |
pr fila_atendimento%rowtype; | |
BEGIN | |
FOR pr IN | |
select * from fila_atendimento where ativo is false | |
LOOP | |
RAISE NOTICE 'trying to delete fila_atendimento id %',pr.id; | |
BEGIN | |
DELETE FROM fila_atendimento WHERE id=pr.id; | |
RAISE NOTICE | |
'Deleted fila_atendimento id: %',pr.id; | |
EXCEPTION | |
WHEN others THEN | |
-- we ignore the error | |
END; | |
END LOOP; | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment