Fixed broken uuid migration

merge-requests/154/head
Eliot Berriot 2018-04-07 17:09:28 +02:00
rodzic 6bf4d46362
commit 33972f1f40
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
2 zmienionych plików z 88 dodań i 9 usunięć

Wyświetl plik

@ -4,7 +4,6 @@ from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import uuid
class Migration(migrations.Migration):
@ -18,17 +17,17 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='album',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AddField(
model_name='artist',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AddField(
model_name='importbatch',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AddField(
model_name='importjob',
@ -38,17 +37,17 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='importjob',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AddField(
model_name='lyrics',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AddField(
model_name='track',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AddField(
model_name='trackfile',
@ -68,12 +67,12 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='trackfile',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AddField(
model_name='work',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
field=models.UUIDField(db_index=True, null=True, unique=True),
),
migrations.AlterField(
model_name='importbatch',

Wyświetl plik

@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import uuid
from django.db import migrations, models
def populate_uuids(apps, schema_editor):
models = [
'Album',
'Artist',
'Importbatch',
'Importjob',
'Lyrics',
'Track',
'Trackfile',
'Work',
]
for m in models:
kls = apps.get_model('music', m)
qs = kls.objects.filter(uuid__isnull=True).only('id')
print('Setting uuids for {} ({} objects)'.format(m, len(qs)))
for o in qs:
o.uuid = uuid.uuid4()
o.save(update_fields=['uuid'])
def rewind(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('music', '0023_auto_20180407_1010'),
]
operations = [
migrations.RunPython(populate_uuids, rewind),
migrations.AlterField(
model_name='album',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name='artist',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name='importbatch',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name='importjob',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name='lyrics',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name='track',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name='trackfile',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name='work',
name='uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
]