Browse Source

Apaga banco antes de migrar flush direto

pull/2056/head
Marcio Mazza 7 years ago
parent
commit
c599db3e9e
  1. 8
      sapl/legacy/migracao_dados.py

8
sapl/legacy/migracao_dados.py

@ -22,6 +22,7 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.management.commands.flush import Command as FlushCommand
from django.db import connections, transaction from django.db import connections, transaction
from django.db.models import Max, Q from django.db.models import Max, Q
from pyaml import UnsafePrettyYAMLDumper from pyaml import UnsafePrettyYAMLDumper
@ -54,7 +55,6 @@ from .scripts.normaliza_dump_mysql import normaliza_dump_mysql
from .timezonesbrasil import get_timezone from .timezonesbrasil import get_timezone
# YAML SETUP ############################################################### # YAML SETUP ###############################################################
def dict_representer(dumper, data): def dict_representer(dumper, data):
return dumper.represent_dict(data.items()) return dumper.represent_dict(data.items())
@ -64,7 +64,7 @@ yaml.add_representer(OrderedDict, dict_representer)
# importante para preservar a ordem ao ler yaml no python 3.5 # importante para preservar a ordem ao ler yaml no python 3.5
def dict_constructor(loader, node): def dict_constructor(loader, node):
return OrderedDict(loader.construct_pairs(node)) return OrderedDict(loader.construct_pairs(node))
yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
dict_constructor) dict_constructor)
@ -830,8 +830,8 @@ def migrar_dados():
# excluindo database antigo. # excluindo database antigo.
info('Excluindo entradas antigas do banco destino.') info('Excluindo entradas antigas do banco destino.')
call([PROJECT_DIR.child('manage.py'), 'flush', flush = FlushCommand()
'--database=default', '--no-input'], stdout=PIPE) flush.handle(database='default', interactive=False, verbosity=0)
# apaga tipos de autor padrão (criados no flush acima) # apaga tipos de autor padrão (criados no flush acima)
TipoAutor.objects.all().delete() TipoAutor.objects.all().delete()

Loading…
Cancel
Save