Add unique embed_key to List model
This commit is contained in:
29
bookwyrm/migrations/0120_list_embed_key.py
Normal file
29
bookwyrm/migrations/0120_list_embed_key.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Generated by Django 3.2.5 on 2021-12-04 10:55
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
def gen_uuid(apps, schema_editor):
|
||||
"""sets an unique UUID for embed_key"""
|
||||
book_lists = apps.get_model("bookwyrm", "List")
|
||||
db_alias = schema_editor.connection.alias
|
||||
for book_list in book_lists.objects.using(db_alias).all():
|
||||
book_list.embed_key = uuid.uuid4()
|
||||
book_list.save(broadcast=False)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0119_user_feed_status_types"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="list",
|
||||
name="embed_key",
|
||||
field=models.UUIDField(editable=False, null=True, unique=True),
|
||||
),
|
||||
migrations.RunPython(gen_uuid, reverse_code=migrations.RunPython.noop),
|
||||
]
|
Reference in New Issue
Block a user