Browse Source

Previne erro de migração se usuário sigi_qs não existir

master 4.0.11
Sesóstris Vieira 4 days ago
parent
commit
8e06b01eb3
  1. 11
      sigi/apps/eventos/migrations/0060_drop_viw_eventos.py
  2. 11
      sigi/apps/eventos/migrations/0062_create_viw_eventos.py
  3. 11
      sigi/apps/eventos/migrations/0066_viw_eventos_paricipante.py

11
sigi/apps/eventos/migrations/0060_drop_viw_eventos.py

@ -4,6 +4,8 @@ from django.db import migrations
SQL_STMT = "DROP VIEW IF EXISTS viw_eventos;" SQL_STMT = "DROP VIEW IF EXISTS viw_eventos;"
SQL_REVERSE_STMT = """ SQL_REVERSE_STMT = """
DO $$
BEGIN
create view viw_eventos as create view viw_eventos as
select e.id, e.nome, e.descricao, e.solicitante, e.data_inicio, e.data_termino, select e.id, e.nome, e.descricao, e.solicitante, e.data_inicio, e.data_termino,
e.local, e.publico_alvo, e.local, e.publico_alvo,
@ -33,7 +35,10 @@ from eventos_evento e
inner join contatos_municipio m on m.codigo_ibge = o.municipio_id inner join contatos_municipio m on m.codigo_ibge = o.municipio_id
inner join contatos_unidadefederativa uf on uf.codigo_ibge = m.uf_id inner join contatos_unidadefederativa uf on uf.codigo_ibge = m.uf_id
inner join eventos_tipoevento t on t.id = e.tipo_evento_id; inner join eventos_tipoevento t on t.id = e.tipo_evento_id;
grant select on viw_eventos to sigi_qs; if exists (select 1 from pg_roles where rolname = 'sigi_qs') then
grant select on viw_eventos to sigi_qs;
end if;
END $$
""" """
@ -43,6 +48,4 @@ class Migration(migrations.Migration):
("eventos", "0059_separa_hora_da_data"), ("eventos", "0059_separa_hora_da_data"),
] ]
operations = [ operations = [migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)]
migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)
]

11
sigi/apps/eventos/migrations/0062_create_viw_eventos.py

@ -3,6 +3,8 @@
from django.db import migrations from django.db import migrations
SQL_STMT = """ SQL_STMT = """
DO $$
BEGIN
create view viw_eventos as create view viw_eventos as
select e.id, e.nome, e.descricao, e.solicitante, (e.data_inicio + e.hora_inicio) as data_inicio, select e.id, e.nome, e.descricao, e.solicitante, (e.data_inicio + e.hora_inicio) as data_inicio,
(e.data_termino + e.hora_termino) as data_termino, e.local, e.publico_alvo, (e.data_termino + e.hora_termino) as data_termino, e.local, e.publico_alvo,
@ -32,7 +34,10 @@ from eventos_evento e
inner join contatos_municipio m on m.codigo_ibge = o.municipio_id inner join contatos_municipio m on m.codigo_ibge = o.municipio_id
inner join contatos_unidadefederativa uf on uf.codigo_ibge = m.uf_id inner join contatos_unidadefederativa uf on uf.codigo_ibge = m.uf_id
inner join eventos_tipoevento t on t.id = e.tipo_evento_id; inner join eventos_tipoevento t on t.id = e.tipo_evento_id;
grant select on viw_eventos to sigi_qs; if exists (select 1 from pg_roles where rolname = 'sigi_qs') then
grant select on viw_eventos to sigi_qs;
end if;
END $$
""" """
SQL_REVERSE_STMT = "DROP VIEW viw_eventos;" SQL_REVERSE_STMT = "DROP VIEW viw_eventos;"
@ -43,6 +48,4 @@ class Migration(migrations.Migration):
("eventos", "0061_alter_evento_data_inicio_alter_evento_data_termino"), ("eventos", "0061_alter_evento_data_inicio_alter_evento_data_termino"),
] ]
operations = [ operations = [migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)]
migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)
]

11
sigi/apps/eventos/migrations/0066_viw_eventos_paricipante.py

@ -3,6 +3,8 @@
from django.db import migrations from django.db import migrations
SQL_STMT = """ SQL_STMT = """
DO $$
BEGIN
create view viw_eventos_participante as create view viw_eventos_participante as
select ep.evento_id as id_evento, select ep.evento_id as id_evento,
ep.casa_legislativa_id as id_casa, ep.casa_legislativa_id as id_casa,
@ -11,7 +13,10 @@ select ep.evento_id as id_evento,
ep.email, ep.email,
ep.local_trabalho ep.local_trabalho
from eventos_participante ep; from eventos_participante ep;
grant select on viw_eventos_participante to sigi_qs; if exists (select 1 from pg_roles where rolname = 'sigi_qs') then
grant select on viw_eventos_participante to sigi_qs;
end if;
END $$
""" """
SQL_REVERSE_STMT = "DROP VIEW viw_eventos_participante;" SQL_REVERSE_STMT = "DROP VIEW viw_eventos_participante;"
@ -22,6 +27,4 @@ class Migration(migrations.Migration):
("eventos", "0065_participantes_visitas"), ("eventos", "0065_participantes_visitas"),
] ]
operations = [ operations = [migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)]
migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)
]

Loading…
Cancel
Save