|
@ -1,10 +1,9 @@ |
|
|
from django.db import connection |
|
|
from django.apps import apps |
|
|
from django.db import models |
|
|
from django.db import connection, models |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import legacy |
|
|
import legacy |
|
|
from parlamentares.models import ( |
|
|
from mesa.models import Legislatura, SessaoLegislativa |
|
|
Legislatura, SessaoLegislativa, NivelInstrucao) |
|
|
from parlamentares.models import NivelInstrucao |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mappings = ( |
|
|
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(): |
|
|
def migrate(): |
|
|
|
|
|
|
|
|
for model, pk, field_pairs in mappings: |
|
|
for model, pk, field_pairs in mappings: |
|
@ -58,4 +82,3 @@ def migrate(): |
|
|
if new.id < old_id: |
|
|
if new.id < old_id: |
|
|
new.delete() |
|
|
new.delete() |
|
|
new = model() |
|
|
new = model() |
|
|
|
|
|
|