From f228c42d92287987d0a355aa68ad5e6000f21a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Wed, 15 May 2024 15:40:47 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20as=20migrations=20para=20funcionar=20?= =?UTF-8?q?em=20uma=20instala=C3=A7=C3=A3o=20limpa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/espacos/migrations/0001_initial.py | 4 +++- .../0008_carga_inicial_reserva_salas.py | 13 ++++++++++--- ...a_anfitria_senado_oficina_remove_convite.py | 13 ++++++++----- .../migrations/0060_drop_viw_eventos.py | 2 +- .../migrations/0022_atualiza_mail_leg.py | 18 ++++++------------ .../migrations/0012_add_user_interlegis.py | 7 ++++++- .../migrations/0015_limpa_servidores_users.py | 13 +++++++++++-- 7 files changed, 45 insertions(+), 25 deletions(-) diff --git a/sigi/apps/espacos/migrations/0001_initial.py b/sigi/apps/espacos/migrations/0001_initial.py index 21e0b61..0094c4b 100644 --- a/sigi/apps/espacos/migrations/0001_initial.py +++ b/sigi/apps/espacos/migrations/0001_initial.py @@ -7,7 +7,9 @@ import django.db.models.deletion class Migration(migrations.Migration): initial = True - dependencies = [] + dependencies = [ + ("eventos", "0053_visita_anfitria_senado_oficina_remove_convite") + ] operations = [ migrations.CreateModel( diff --git a/sigi/apps/espacos/migrations/0008_carga_inicial_reserva_salas.py b/sigi/apps/espacos/migrations/0008_carga_inicial_reserva_salas.py index 3378ddb..c1bfcd4 100644 --- a/sigi/apps/espacos/migrations/0008_carga_inicial_reserva_salas.py +++ b/sigi/apps/espacos/migrations/0008_carga_inicial_reserva_salas.py @@ -11,10 +11,17 @@ def forward(apps, schema_editor): Espaco = apps.get_model("espacos", "Espaco") DEPARA_SALAS = [(5, 62), (4, 66), (3, 63)] + if not Espaco.objects.filter(id__in=[v[0] for v in DEPARA_SALAS]).exists(): + # As salas não existem. Não há nada a fazer. + return + for espaco_id, id_sala in DEPARA_SALAS: - espaco = Espaco.objects.get(id=espaco_id) - espaco.id_sala = id_sala - espaco.save() + try: + espaco = Espaco.objects.get(id=espaco_id) + espaco.id_sala = id_sala + espaco.save() + except Espaco.DoesNotExist: + pass if ( settings.RESERVA_SALA_BASE_URL is None diff --git a/sigi/apps/eventos/migrations/0053_visita_anfitria_senado_oficina_remove_convite.py b/sigi/apps/eventos/migrations/0053_visita_anfitria_senado_oficina_remove_convite.py index 6839612..4f037bd 100644 --- a/sigi/apps/eventos/migrations/0053_visita_anfitria_senado_oficina_remove_convite.py +++ b/sigi/apps/eventos/migrations/0053_visita_anfitria_senado_oficina_remove_convite.py @@ -10,11 +10,14 @@ def forwards(apps, schema_editor): # Define casa_anfitria = senado para todas as visitas # Gertik #165751 (2) - senado = Orgao.objects.get(tipo__sigla="SF") - - Evento.objects.filter(tipo_evento__categoria="V").update( - casa_anfitria=senado - ) + try: + senado = Orgao.objects.get(tipo__sigla="SF") + Evento.objects.filter(tipo_evento__categoria="V").update( + casa_anfitria=senado + ) + except Orgao.DoesNotExist: + # Não existe o órgão SF, então basta seguir + pass # Deletar todos os convites (casas convidadas) das oficinas que têm vínculo # com o saberes moodle_courseid not NULL diff --git a/sigi/apps/eventos/migrations/0060_drop_viw_eventos.py b/sigi/apps/eventos/migrations/0060_drop_viw_eventos.py index cb11ab3..ebdf608 100644 --- a/sigi/apps/eventos/migrations/0060_drop_viw_eventos.py +++ b/sigi/apps/eventos/migrations/0060_drop_viw_eventos.py @@ -2,7 +2,7 @@ from django.db import migrations -SQL_STMT = "DROP VIEW viw_eventos;" +SQL_STMT = "DROP VIEW IF EXISTS viw_eventos;" SQL_REVERSE_STMT = """ create view viw_eventos as select e.id, e.nome, e.descricao, e.solicitante, e.data_inicio, e.data_termino, diff --git a/sigi/apps/servicos/migrations/0022_atualiza_mail_leg.py b/sigi/apps/servicos/migrations/0022_atualiza_mail_leg.py index 0a3d452..3f5027d 100644 --- a/sigi/apps/servicos/migrations/0022_atualiza_mail_leg.py +++ b/sigi/apps/servicos/migrations/0022_atualiza_mail_leg.py @@ -5,7 +5,11 @@ from django.db import migrations def mailleg_fw(apps, schema_editor): TipoServico = apps.get_model("servicos", "TipoServico") - tipo = TipoServico.objects.get(sigla__icontains="mail") + try: + tipo = TipoServico.objects.get(sigla__icontains="mail") + except TipoServico.DoesNotExist: + return + tipo.tipo_rancher = "emailleg" tipo.arquivo_rancher = "mail.json" tipo.spec_rancher = "mail" @@ -13,21 +17,11 @@ def mailleg_fw(apps, schema_editor): tipo.save() -def mailleg_rw(apps, schema_editor): - TipoServico = apps.get_model("servicos", "TipoServico") - tipo = TipoServico.objects.get(sigla__icontains="mail") - tipo.tipo_rancher = "" - tipo.arquivo_rancher = "" - tipo.spec_rancher = "" - tipo.prefixo_padrao = "" - tipo.save() - - class Migration(migrations.Migration): dependencies = [ ("servicos", "0021_remove_servico_unique_instance_and_more"), ] operations = [ - migrations.RunPython(mailleg_fw, mailleg_rw), + migrations.RunPython(mailleg_fw, migrations.RunPython.noop), ] diff --git a/sigi/apps/servidores/migrations/0012_add_user_interlegis.py b/sigi/apps/servidores/migrations/0012_add_user_interlegis.py index 16bbf61..a1fdbcb 100644 --- a/sigi/apps/servidores/migrations/0012_add_user_interlegis.py +++ b/sigi/apps/servidores/migrations/0012_add_user_interlegis.py @@ -8,7 +8,12 @@ def forwards_migration(apps, schema_editor): Servidor = apps.get_model("servidores", "Servidor") User = get_user_model() - sigi = Servidor.objects.get(sigi=True) + try: + sigi = Servidor.objects.get(sigi=True) + except Servidor.DoesNotExist: + # Cria o Servidor do SIGI + sigi = Servidor(nome_completo="Administrador do SIGI", sigi=True) + sigi.save() if sigi.user is not None: # everything is already fine diff --git a/sigi/apps/servidores/migrations/0015_limpa_servidores_users.py b/sigi/apps/servidores/migrations/0015_limpa_servidores_users.py index 628af83..d548001 100644 --- a/sigi/apps/servidores/migrations/0015_limpa_servidores_users.py +++ b/sigi/apps/servidores/migrations/0015_limpa_servidores_users.py @@ -24,6 +24,10 @@ def update_user_from_ldap(user, ldap_attrs): def forwards(apps, schema_editor): + if not hasattr(settings, "AUTH_LDAP_SERVER_URI"): + # Não está conectado ao LDAP. Nada a fazer + return + User = get_user_model() coder = _DeepStringCoder("utf8") @@ -296,8 +300,12 @@ def forwards(apps, schema_editor): ] for source_id, target_id in manuais: - servidor_source = Servidor.objects.get(id=source_id) - servidor_target = Servidor.objects.get(id=target_id) + try: + servidor_source = Servidor.objects.get(id=source_id) + servidor_target = Servidor.objects.get(id=target_id) + except Servidor.DoesNotExist: + # Se um não existe, não há nada a fazer + continue print( f"\tJoining {servidor_source.nome_completo} " f"to {servidor_target.nome_completo}" @@ -307,6 +315,7 @@ def forwards(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ + ("auth", "0001_initial"), ("servidores", "0014_servidor_ldap_dn_alter_servidor_user"), ]