reversible migrations.

This commit is contained in:
Jonas Winkler 2020-11-22 11:41:13 +01:00
parent 532d5c1744
commit 388e5b56de

View File

@ -1,4 +1,6 @@
# Generated by Django 3.1.3 on 2020-11-07 12:35 # Generated by Django 3.1.3 on 2020-11-07 12:35
import uuid
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -20,6 +22,14 @@ def make_index(apps, schema_editor):
print(" --> Cannot create document index.") print(" --> Cannot create document index.")
def logs_set_default_group(apps, schema_editor):
Log = apps.get_model('documents', 'Log')
for log in Log.objects.all():
if log.group is None:
log.group = uuid.uuid4()
log.save()
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
@ -85,6 +95,10 @@ class Migration(migrations.Migration):
name='group', name='group',
field=models.UUIDField(blank=True, null=True), field=models.UUIDField(blank=True, null=True),
), ),
migrations.RunPython(
code=django.db.migrations.operations.special.RunPython.noop,
reverse_code=logs_set_default_group
),
migrations.RunPython( migrations.RunPython(
code=make_index, code=make_index,
reverse_code=django.db.migrations.operations.special.RunPython.noop, reverse_code=django.db.migrations.operations.special.RunPython.noop,