primary keys from character strings to integers, and makes corresponding code changes. This was prompted by database limitations discovered when trying to make DocAlias use a m2m document field; with 255 long strings as primary keys for Document and DocAlias this violated the MySQL database limitations. Changing the primary keys to integers should also improve efficiency. Due to the data migrations which create the new integer primary keys and adds corresponding integer foreign keys matching the previous string foreign keys in all tables having foreign keys to Document and DocAlias, some of these migrations take a long time. The total set of migrations are expected to have a runtime on the order of 2 hours. - Legacy-Id: 16237
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.11.20 on 2019-05-21 14:27
|
|
from __future__ import unicode_literals
|
|
|
|
import sys
|
|
|
|
from tqdm import tqdm
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
def forward(apps, schema_editor):
|
|
|
|
Document = apps.get_model('doc','Document')
|
|
CommunityList = apps.get_model('community', 'CommunityList')
|
|
CommunityListDocs = apps.get_model('community', 'CommunityListDocs')
|
|
SearchRule = apps.get_model('community', 'SearchRule')
|
|
SearchRuleDocs = apps.get_model('community', 'SearchRuleDocs')
|
|
|
|
# Document id fixup ------------------------------------------------------------
|
|
|
|
objs = Document.objects.in_bulk()
|
|
nameid = { o.name: o.id for id, o in objs.iteritems() }
|
|
|
|
sys.stderr.write('\n')
|
|
|
|
sys.stderr.write(' %s.%s:\n' % (CommunityList.__name__, 'added_docs'))
|
|
count = 0
|
|
for l in tqdm(CommunityList.objects.all()):
|
|
for d in l.added_docs.all():
|
|
count += 1
|
|
CommunityListDocs.objects.get_or_create(communitylist=l, document_id=nameid[d.name])
|
|
sys.stderr.write(' %s CommunityListDocs objects created\n' % (count, ))
|
|
|
|
sys.stderr.write(' %s.%s:\n' % (SearchRule.__name__, 'name_contains_index'))
|
|
count = 0
|
|
for r in tqdm(SearchRule.objects.all()):
|
|
for d in r.name_contains_index.all():
|
|
count += 1
|
|
SearchRuleDocs.objects.get_or_create(searchrule=r, document_id=nameid[d.name])
|
|
sys.stderr.write(' %s SearchRuleDocs objects created\n' % (count, ))
|
|
|
|
def reverse(apps, schema_editor):
|
|
pass
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('community', '0003_add_communitylist_docs2_m2m'),
|
|
('doc', '0014_set_document_docalias_id'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(forward, reverse),
|
|
]
|