datatracker/ietf/doc/migrations/0014_set_document_docalias_id.py
Henrik Levkowetz 815602351f This is a series of 50 migrations that changes the Document and DocAlias
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
2019-06-10 11:32:46 +00:00

36 lines
779 B
Python

# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-08 08:42
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')
sys.stderr.write('\n')
for i, d in enumerate(tqdm(Document.objects.all()), start=1):
d.id = i
d.save()
DocAlias = apps.get_model('doc','DocAlias')
for i, d in enumerate(tqdm(DocAlias.objects.all()), start=1):
d.id = i
d.save()
def reverse(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('doc', '0013_add_document_docalias_id'),
]
operations = [
migrations.RunPython(forward, reverse),
]