Commit 1ffb74cc9f7f0935068a3446160b6d9593b9bf65
1 parent
aabd9dea
Exists in
master
by Eriksen: Corrigido problemas com a restauração de triggers e constraints das …
…tabelas public.uf e public.municipio em decorrência da limpeza do banco de dados
Showing
2 changed files
with
161 additions
and
0 deletions
Show diff stats
ieducar/misc/database/deltas/5_corrige_triggers_constrainst.sql
0 → 100644
| @@ -0,0 +1,76 @@ | @@ -0,0 +1,76 @@ | ||
| 1 | +-- // | ||
| 2 | + | ||
| 3 | +-- | ||
| 4 | +-- Restaura triggers e constraints das tabelas public.municipio e public.uf | ||
| 5 | +-- que foram totalmente desabilitadas pelos scripts de limpeza de banco de | ||
| 6 | +-- dados. O schema de todos os comandos é o public. | ||
| 7 | +-- | ||
| 8 | +-- Nenhum efeito colateral foi relatado por conta dessas remoções. Este | ||
| 9 | +-- delta visa apenas a reestabelecer a eventual consistência que estas | ||
| 10 | +-- triggers e constraint dão. | ||
| 11 | +-- | ||
| 12 | +-- Para visualizar a diferença e ter um número que indique a quantidade | ||
| 13 | +-- de triggers habilitadas, execute a seguinte query em uma base do | ||
| 14 | +-- i-Educar 1.0.2 (rev. 57) e outra do primeiro beta do i-Educar 1.1.0 | ||
| 15 | +-- (rev. 80). Substitua ? por 'municipio' e depois por 'uf'. | ||
| 16 | +-- | ||
| 17 | +-- Quantidades esperadas (1.0.2 e 1.1.0-beta1, respectivamente): | ||
| 18 | +-- * uf: 16/12 | ||
| 19 | +-- * municipio: 26/6 | ||
| 20 | +-- | ||
| 21 | +-- <code> | ||
| 22 | +-- (SELECT | ||
| 23 | +-- count(pg_trigger.*) | ||
| 24 | +-- FROM | ||
| 25 | +-- pg_catalog.pg_class, pg_catalog.pg_trigger | ||
| 26 | +-- WHERE | ||
| 27 | +-- pg_class.relname = '?' | ||
| 28 | +-- AND pg_class.oid = pg_trigger.tgrelid) | ||
| 29 | +-- <code> | ||
| 30 | +-- | ||
| 31 | +-- O script que não reestabeleceu as triggers e constraints foi o da | ||
| 32 | +-- terceira versão (2_populate_basic_data.sql@6516), disponível no ticket #37: | ||
| 33 | +-- {@link http://svn.softwarepublico.gov.br/trac/ieducar/ticket/37#change_1}. | ||
| 34 | +-- | ||
| 35 | +-- @author Eriksen Costa Paixão <eriksen.paixao_bs@cobra.com.br> | ||
| 36 | +-- @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL | ||
| 37 | +-- @version $Id$ | ||
| 38 | +-- | ||
| 39 | + | ||
| 40 | +CREATE TRIGGER trg_bef_municipio_historico | ||
| 41 | + BEFORE UPDATE ON municipio | ||
| 42 | + FOR EACH ROW | ||
| 43 | + EXECUTE PROCEDURE historico.fcn_grava_historico_municipio(); | ||
| 44 | + | ||
| 45 | +CREATE TRIGGER trg_delete_municipio_historico | ||
| 46 | + AFTER DELETE ON municipio | ||
| 47 | + FOR EACH ROW | ||
| 48 | + EXECUTE PROCEDURE historico.fcn_delete_grava_historico_municipio(); | ||
| 49 | + | ||
| 50 | +ALTER TABLE ONLY municipio | ||
| 51 | + ADD CONSTRAINT fk_logradouro_municipio FOREIGN KEY (idmun) REFERENCES municipio(idmun); | ||
| 52 | + | ||
| 53 | +ALTER TABLE ONLY municipio | ||
| 54 | + ADD CONSTRAINT fk_municipio_municipiopai FOREIGN KEY (idmun_pai) REFERENCES municipio(idmun); | ||
| 55 | + | ||
| 56 | +ALTER TABLE ONLY municipio | ||
| 57 | + ADD CONSTRAINT fk_municipio_sistema_idpes_cad FOREIGN KEY (idpes_cad) REFERENCES cadastro.pessoa(idpes) ON DELETE SET NULL; | ||
| 58 | + | ||
| 59 | +ALTER TABLE ONLY municipio | ||
| 60 | + ADD CONSTRAINT fk_municipio_sistema_idpes_rev FOREIGN KEY (idpes_rev) REFERENCES cadastro.pessoa(idpes) ON DELETE SET NULL; | ||
| 61 | + | ||
| 62 | +ALTER TABLE ONLY municipio | ||
| 63 | + ADD CONSTRAINT fk_municipio_sistema_idsis_cad FOREIGN KEY (idsis_cad) REFERENCES acesso.sistema(idsis) ON DELETE SET NULL; | ||
| 64 | + | ||
| 65 | +ALTER TABLE ONLY municipio | ||
| 66 | + ADD CONSTRAINT fk_municipio_sistema_idsis_rev FOREIGN KEY (idsis_rev) REFERENCES acesso.sistema(idsis) ON DELETE SET NULL; | ||
| 67 | + | ||
| 68 | +ALTER TABLE ONLY municipio | ||
| 69 | + ADD CONSTRAINT fk_municipio_uf FOREIGN KEY (sigla_uf) REFERENCES uf(sigla_uf); | ||
| 70 | + | ||
| 71 | +ALTER TABLE ONLY uf | ||
| 72 | + ADD CONSTRAINT fk_uf_pais FOREIGN KEY (idpais) REFERENCES pais(idpais); | ||
| 73 | + | ||
| 74 | +-- //@UNDO | ||
| 75 | + | ||
| 76 | +-- // |
ieducar/misc/database/ieducar.sql
| @@ -19158,6 +19158,7 @@ INSERT INTO changelog VALUES (2, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '2_popula | @@ -19158,6 +19158,7 @@ INSERT INTO changelog VALUES (2, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '2_popula | ||
| 19158 | INSERT INTO changelog VALUES (1, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '1_cria_schema_inicial.sql'); | 19158 | INSERT INTO changelog VALUES (1, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '1_cria_schema_inicial.sql'); |
| 19159 | INSERT INTO changelog VALUES (3, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '3_corrige_sequences.sql'); | 19159 | INSERT INTO changelog VALUES (3, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '3_corrige_sequences.sql'); |
| 19160 | INSERT INTO changelog VALUES (4, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '4_permissoes_usuario_tipo_biblioteca.sql'); | 19160 | INSERT INTO changelog VALUES (4, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '4_permissoes_usuario_tipo_biblioteca.sql'); |
| 19161 | +INSERT INTO changelog VALUES (5, 'Main', 'NOW()', 'NOW()', 'dbdeploy', '5_corrige_triggers_constrainst.sql'); | ||
| 19161 | 19162 | ||
| 19162 | 19163 | ||
| 19163 | -- | 19164 | -- |
| @@ -30055,6 +30056,16 @@ CREATE TRIGGER trg_bef_logradouro_historico | @@ -30055,6 +30056,16 @@ CREATE TRIGGER trg_bef_logradouro_historico | ||
| 30055 | 30056 | ||
| 30056 | 30057 | ||
| 30057 | -- | 30058 | -- |
| 30059 | +-- Name: trg_bef_municipio_historico; Type: TRIGGER; Schema: public; Owner: - | ||
| 30060 | +-- | ||
| 30061 | + | ||
| 30062 | +CREATE TRIGGER trg_bef_municipio_historico | ||
| 30063 | + BEFORE UPDATE ON municipio | ||
| 30064 | + FOR EACH ROW | ||
| 30065 | + EXECUTE PROCEDURE historico.fcn_grava_historico_municipio(); | ||
| 30066 | + | ||
| 30067 | + | ||
| 30068 | +-- | ||
| 30058 | -- Name: trg_delete_bairro_historico; Type: TRIGGER; Schema: public; Owner: - | 30069 | -- Name: trg_delete_bairro_historico; Type: TRIGGER; Schema: public; Owner: - |
| 30059 | -- | 30070 | -- |
| 30060 | 30071 | ||
| @@ -30074,6 +30085,16 @@ CREATE TRIGGER trg_delete_logradouro_historico | @@ -30074,6 +30085,16 @@ CREATE TRIGGER trg_delete_logradouro_historico | ||
| 30074 | EXECUTE PROCEDURE historico.fcn_delete_grava_historico_logradouro(); | 30085 | EXECUTE PROCEDURE historico.fcn_delete_grava_historico_logradouro(); |
| 30075 | 30086 | ||
| 30076 | 30087 | ||
| 30088 | +-- | ||
| 30089 | +-- Name: trg_delete_municipio_historico; Type: TRIGGER; Schema: public; Owner: - | ||
| 30090 | +-- | ||
| 30091 | + | ||
| 30092 | +CREATE TRIGGER trg_delete_municipio_historico | ||
| 30093 | + AFTER DELETE ON municipio | ||
| 30094 | + FOR EACH ROW | ||
| 30095 | + EXECUTE PROCEDURE historico.fcn_delete_grava_historico_municipio(); | ||
| 30096 | + | ||
| 30097 | + | ||
| 30077 | SET search_path = urbano, pg_catalog; | 30098 | SET search_path = urbano, pg_catalog; |
| 30078 | 30099 | ||
| 30079 | -- | 30100 | -- |
| @@ -35539,6 +35560,14 @@ ALTER TABLE ONLY logradouro_fonetico | @@ -35539,6 +35560,14 @@ ALTER TABLE ONLY logradouro_fonetico | ||
| 35539 | 35560 | ||
| 35540 | 35561 | ||
| 35541 | -- | 35562 | -- |
| 35563 | +-- Name: fk_logradouro_municipio; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35564 | +-- | ||
| 35565 | + | ||
| 35566 | +ALTER TABLE ONLY municipio | ||
| 35567 | + ADD CONSTRAINT fk_logradouro_municipio FOREIGN KEY (idmun) REFERENCES municipio(idmun); | ||
| 35568 | + | ||
| 35569 | + | ||
| 35570 | +-- | ||
| 35542 | -- Name: fk_logradouro_sistema_idpes_cad; Type: FK CONSTRAINT; Schema: public; Owner: - | 35571 | -- Name: fk_logradouro_sistema_idpes_cad; Type: FK CONSTRAINT; Schema: public; Owner: - |
| 35543 | -- | 35572 | -- |
| 35544 | 35573 | ||
| @@ -35579,6 +35608,54 @@ ALTER TABLE ONLY logradouro | @@ -35579,6 +35608,54 @@ ALTER TABLE ONLY logradouro | ||
| 35579 | 35608 | ||
| 35580 | 35609 | ||
| 35581 | -- | 35610 | -- |
| 35611 | +-- Name: fk_municipio_municipiopai; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35612 | +-- | ||
| 35613 | + | ||
| 35614 | +ALTER TABLE ONLY municipio | ||
| 35615 | + ADD CONSTRAINT fk_municipio_municipiopai FOREIGN KEY (idmun_pai) REFERENCES municipio(idmun); | ||
| 35616 | + | ||
| 35617 | + | ||
| 35618 | +-- | ||
| 35619 | +-- Name: fk_municipio_sistema_idpes_cad; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35620 | +-- | ||
| 35621 | + | ||
| 35622 | +ALTER TABLE ONLY municipio | ||
| 35623 | + ADD CONSTRAINT fk_municipio_sistema_idpes_cad FOREIGN KEY (idpes_cad) REFERENCES cadastro.pessoa(idpes) ON DELETE SET NULL; | ||
| 35624 | + | ||
| 35625 | + | ||
| 35626 | +-- | ||
| 35627 | +-- Name: fk_municipio_sistema_idpes_rev; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35628 | +-- | ||
| 35629 | + | ||
| 35630 | +ALTER TABLE ONLY municipio | ||
| 35631 | + ADD CONSTRAINT fk_municipio_sistema_idpes_rev FOREIGN KEY (idpes_rev) REFERENCES cadastro.pessoa(idpes) ON DELETE SET NULL; | ||
| 35632 | + | ||
| 35633 | + | ||
| 35634 | +-- | ||
| 35635 | +-- Name: fk_municipio_sistema_idsis_cad; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35636 | +-- | ||
| 35637 | + | ||
| 35638 | +ALTER TABLE ONLY municipio | ||
| 35639 | + ADD CONSTRAINT fk_municipio_sistema_idsis_cad FOREIGN KEY (idsis_cad) REFERENCES acesso.sistema(idsis) ON DELETE SET NULL; | ||
| 35640 | + | ||
| 35641 | + | ||
| 35642 | +-- | ||
| 35643 | +-- Name: fk_municipio_sistema_idsis_rev; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35644 | +-- | ||
| 35645 | + | ||
| 35646 | +ALTER TABLE ONLY municipio | ||
| 35647 | + ADD CONSTRAINT fk_municipio_sistema_idsis_rev FOREIGN KEY (idsis_rev) REFERENCES acesso.sistema(idsis) ON DELETE SET NULL; | ||
| 35648 | + | ||
| 35649 | + | ||
| 35650 | +-- | ||
| 35651 | +-- Name: fk_municipio_uf; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35652 | +-- | ||
| 35653 | + | ||
| 35654 | +ALTER TABLE ONLY municipio | ||
| 35655 | + ADD CONSTRAINT fk_municipio_uf FOREIGN KEY (sigla_uf) REFERENCES uf(sigla_uf); | ||
| 35656 | + | ||
| 35657 | + | ||
| 35658 | +-- | ||
| 35582 | -- Name: fk_setor_idsetredir; Type: FK CONSTRAINT; Schema: public; Owner: - | 35659 | -- Name: fk_setor_idsetredir; Type: FK CONSTRAINT; Schema: public; Owner: - |
| 35583 | -- | 35660 | -- |
| 35584 | 35661 | ||
| @@ -35595,6 +35672,14 @@ ALTER TABLE ONLY setor | @@ -35595,6 +35672,14 @@ ALTER TABLE ONLY setor | ||
| 35595 | 35672 | ||
| 35596 | 35673 | ||
| 35597 | -- | 35674 | -- |
| 35675 | +-- Name: fk_uf_pais; Type: FK CONSTRAINT; Schema: public; Owner: - | ||
| 35676 | +-- | ||
| 35677 | + | ||
| 35678 | +ALTER TABLE ONLY uf | ||
| 35679 | + ADD CONSTRAINT fk_uf_pais FOREIGN KEY (idpais) REFERENCES pais(idpais); | ||
| 35680 | + | ||
| 35681 | + | ||
| 35682 | +-- | ||
| 35598 | -- Name: fk_vila_municipio; Type: FK CONSTRAINT; Schema: public; Owner: - | 35683 | -- Name: fk_vila_municipio; Type: FK CONSTRAINT; Schema: public; Owner: - |
| 35599 | -- | 35684 | -- |
| 35600 | 35685 |