From 7f24bea073ed3242533f3e86c217ec11816f5f46 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Mon, 3 Apr 2017 14:24:47 -0300 Subject: [PATCH] Comando do manage.py para recriar constraints Signed-off-by: Luciano Almeida --- .../legacy/management/commands/recria_constraints.py | 12 ++++++++++++ sapl/legacy/migration.py | 4 ++-- sapl/legacy/scripts/migra_um_db.sh | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 sapl/legacy/management/commands/recria_constraints.py diff --git a/sapl/legacy/management/commands/recria_constraints.py b/sapl/legacy/management/commands/recria_constraints.py new file mode 100644 index 000000000..9e999e5f6 --- /dev/null +++ b/sapl/legacy/management/commands/recria_constraints.py @@ -0,0 +1,12 @@ +from django.core.management.base import BaseCommand + +from sapl.legacy.migration import recria_constraints + + +class Command(BaseCommand): + + help = (u'Recria constraints do PostgreSQL excluidas durante ' + 'migração de dados') + + def handle(self, *args, **options): + recria_constraints() diff --git a/sapl/legacy/migration.py b/sapl/legacy/migration.py index 60ab48e23..cb24664b0 100644 --- a/sapl/legacy/migration.py +++ b/sapl/legacy/migration.py @@ -236,7 +236,7 @@ def delete_constraints(model): (table, r[0])) -def recreate_constraints(): +def recria_constraints(): constraints = Constraint.objects.all() for con in constraints: if con.tipo_constraint == 'one_to_one': @@ -459,7 +459,7 @@ class DataMigrator: for obj in self.to_delete: msg = 'A entrada de PK %s da model %s não pode ser ' \ 'excluida' % (obj.pk, obj._meta.model_name) - descricao = 'Um ou mais objetos protegidos ' + descricao = 'Um ou mais objetos protegidos' warn(msg + ' => ' + descricao) save_relation(obj=obj, problema=msg, descricao=descricao, eh_stub=False) diff --git a/sapl/legacy/scripts/migra_um_db.sh b/sapl/legacy/scripts/migra_um_db.sh index 26240d8d4..f55dfb53a 100755 --- a/sapl/legacy/scripts/migra_um_db.sh +++ b/sapl/legacy/scripts/migra_um_db.sh @@ -23,3 +23,9 @@ echo "--- MIGRACAO DE DADOS ---" | tee -a $LOG echo >> $LOG DATABASE_NAME=$1 ./manage.py migracao_25_31 -f --settings sapl.legacy_migration_settings |& tee -a $LOG echo >> $LOG + + +echo "--- RECRIANDO CONSTRAINTS ---" | tee -a $LOG +echo >> $LOG +DATABASE_NAME=$1 ./manage.py recria_constraints --settings sapl.legacy_migration_settings |& tee -a $LOG +echo >> $LOG