Browse Source

Add checks for models structure for migration

pull/6/head
Marcio Mazza 10 years ago
parent
commit
96e5f5f770
  1. 35
      legacy/scripts/migrate.py

35
legacy/legacy_migration.py → 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()
Loading…
Cancel
Save