From ef47214c86b1b943da76a4afc417db258ee633f2 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Fri, 24 Feb 2017 11:13:09 -0300 Subject: [PATCH] =?UTF-8?q?Muda=20jeito=20de=20exclus=C3=A3o=20inicial=20d?= =?UTF-8?q?o=20banco?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- sapl/legacy/migration.py | 63 ++++++++++------------------------------ 1 file changed, 15 insertions(+), 48 deletions(-) diff --git a/sapl/legacy/migration.py b/sapl/legacy/migration.py index e0ba0c679..1228252e9 100644 --- a/sapl/legacy/migration.py +++ b/sapl/legacy/migration.py @@ -27,7 +27,6 @@ from sapl.norma.models import AssuntoNorma, NormaJuridica, VinculoNormaJuridica from sapl.parlamentares.models import Parlamentar from sapl.protocoloadm.models import Protocolo, StatusTramitacaoAdministrativo from sapl.sessao.models import ExpedienteMateria, OrdemDia, SessaoPlenaria -from sapl.rules.apps import revision_pre_delete_signal from sapl.utils import normalize # BASE ###################################################################### @@ -382,18 +381,22 @@ class DataMigrator: def migrate(self, obj=appconfs): # warning: model/app migration order is of utmost importance - self.to_delete = [] exec_sql_file('sapl/legacy/scripts/fix_tables.sql', 'legacy') - with desconecta_revisao_delete( - signal=signals.pre_delete, - receiver=revision_pre_delete_signal, - senders=[VinculoNormaJuridica, - ProblemaMigracao, get_user_model()]): - VinculoNormaJuridica.objects.all().delete() - ProblemaMigracao.objects.all().delete() - get_user_model().objects.exclude(is_superuser=True).delete() - Revision.objects.all().delete() - Version.objects.all().delete() + self.to_delete = [] + + # excluindo database antigo. + info('Todos os dados do banco serão excluidos. ' + 'Recomendamos que faça backup do banco sapl antes de continuar.') + info('Deseja continuar? [s/n]') + resposta = input() + if resposta.lower() in ['s', 'sim', 'y', 'yes']: + pass + else: + info('Migração cancelada.') + return 0 + info('Excluindo entradas antigas do banco.') + call(['./manage.py', 'flush', '--settings=sapl.settings', + '--database=default', '--no-input'], stdout=PIPE) info('Começando migração: %s...' % obj) self._do_migrate(obj) @@ -714,39 +717,3 @@ def make_with_log(model, _quantity=None, make_m2m=False, **attrs): return stub make_with_log.required = foreign_key_required - -# DISCONNECT SIGNAL TO DELETE ################################################ - - -class desconecta_revisao_delete(): - def __init__(self, signal, receiver, senders=[], dispatch_uid=None): - self.signal = signal - self.receiver = receiver - self.senders = senders - self.dispatch_uid = dispatch_uid - - def disconnect_signal(self, model): - self.signal.disconnect( - receiver=self.receiver, - sender=model, - dispatch_uid=self.dispatch_uid, - weak=False,) - - def connect_signal(self, model): - self.signal.connect( - receiver=self.receiver, - sender=model, - dispatch_uid=self.dispatch_uid, - weak=False,) - - def __enter__(self): - for sender in self.senders: - self.disconnect_signal(sender) - for related in sender._meta.get_all_related_objects_with_model(): - self.disconnect_signal(related[0].related_model) - - def __exit__(self, type, value, traceback): - for sender in self.senders: - self.connect_signal(sender) - for related in sender._meta.get_all_related_objects_with_model(): - self.connect_signal(related[0].related_model)