diff --git a/sigi/apps/eventos/migrations/0060_drop_viw_eventos.py b/sigi/apps/eventos/migrations/0060_drop_viw_eventos.py index ebdf608..cc89ea7 100644 --- a/sigi/apps/eventos/migrations/0060_drop_viw_eventos.py +++ b/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_REVERSE_STMT = """ +DO $$ +BEGIN create view viw_eventos as select e.id, e.nome, e.descricao, e.solicitante, e.data_inicio, e.data_termino, 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_unidadefederativa uf on uf.codigo_ibge = m.uf_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"), ] - operations = [ - migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT) - ] + operations = [migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)] diff --git a/sigi/apps/eventos/migrations/0062_create_viw_eventos.py b/sigi/apps/eventos/migrations/0062_create_viw_eventos.py index 3dfbbf4..e04a0dd 100644 --- a/sigi/apps/eventos/migrations/0062_create_viw_eventos.py +++ b/sigi/apps/eventos/migrations/0062_create_viw_eventos.py @@ -3,6 +3,8 @@ from django.db import migrations SQL_STMT = """ +DO $$ +BEGIN create view viw_eventos as 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, @@ -32,7 +34,10 @@ from eventos_evento e 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 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;" @@ -43,6 +48,4 @@ class Migration(migrations.Migration): ("eventos", "0061_alter_evento_data_inicio_alter_evento_data_termino"), ] - operations = [ - migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT) - ] + operations = [migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)] diff --git a/sigi/apps/eventos/migrations/0066_viw_eventos_paricipante.py b/sigi/apps/eventos/migrations/0066_viw_eventos_paricipante.py index 6a40dee..18b262c 100644 --- a/sigi/apps/eventos/migrations/0066_viw_eventos_paricipante.py +++ b/sigi/apps/eventos/migrations/0066_viw_eventos_paricipante.py @@ -3,6 +3,8 @@ from django.db import migrations SQL_STMT = """ +DO $$ +BEGIN create view viw_eventos_participante as select ep.evento_id as id_evento, ep.casa_legislativa_id as id_casa, @@ -11,7 +13,10 @@ select ep.evento_id as id_evento, ep.email, ep.local_trabalho 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;" @@ -22,6 +27,4 @@ class Migration(migrations.Migration): ("eventos", "0065_participantes_visitas"), ] - operations = [ - migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT) - ] + operations = [migrations.RunSQL(sql=SQL_STMT, reverse_sql=SQL_REVERSE_STMT)]