diff --git a/legacy/legacy_migration.py b/legacy/scripts/migrate.py similarity index 70% rename from legacy/legacy_migration.py rename to legacy/scripts/migrate.py index dabdb00c7..24f64bf20 100644 --- a/legacy/legacy_migration.py +++ b/legacy/scripts/migrate.py @@ -1,10 +1,9 @@ -from django.db import connection -from django.db import models - +from django.apps import apps +from django.db import connection, models import legacy -from parlamentares.models import ( - Legislatura, SessaoLegislativa, NivelInstrucao) +from mesa.models import Legislatura, SessaoLegislativa +from parlamentares.models import NivelInstrucao mappings = ( @@ -28,6 +27,31 @@ mappings = ( ) +appconfs = [apps.get_app_config(n) for n in [ + 'mesa', + 'parlamentares', + 'comissoes', + 'sessao', + 'materia', + 'norma', + 'lexml', + 'protocoloadm', ]] +name_sets = [set(m.__name__ for m in ac.get_models()) for ac in appconfs] + +# apps do not overlap +for s1 in name_sets: + for s2 in name_sets: + if s1 is not s2: + assert not s1.intersection(s2) + +# apps include all legacy models +legacy_model_names = set(m.__name__ for m in apps.get_app_config('legacy').get_models()) +all_names = set() +for s1 in name_sets: + all_names = all_names.union(s1) +assert all_names == legacy_model_names + + def migrate(): for model, pk, field_pairs in mappings: @@ -58,4 +82,3 @@ def migrate(): if new.id < old_id: new.delete() new = model() -