|
| 1 | +# Generated by Django 4.2.23 on 2026-01-21 10:39 |
| 2 | + |
| 3 | +import uuid |
| 4 | + |
| 5 | +from django.db import migrations |
| 6 | +from django.db import models |
| 7 | +from django.db.backends.base.schema import BaseDatabaseSchemaEditor |
| 8 | +from django.db.migrations.state import StateApps |
| 9 | + |
| 10 | + |
| 11 | +def generate_unique_uid( |
| 12 | + apps: StateApps, schema_editor: BaseDatabaseSchemaEditor |
| 13 | +) -> None: |
| 14 | + person = apps.get_model("app", "Person") |
| 15 | + |
| 16 | + for p in person.objects.all(): |
| 17 | + p.uid = uuid.uuid4() |
| 18 | + p.save() |
| 19 | + |
| 20 | + |
| 21 | +class Migration(migrations.Migration): |
| 22 | + |
| 23 | + dependencies = [ |
| 24 | + ("app", "0005_electiondistrict_person_election_district"), |
| 25 | + ] |
| 26 | + |
| 27 | + operations = [ |
| 28 | + migrations.AddField( |
| 29 | + model_name="person", |
| 30 | + name="is_public", |
| 31 | + field=models.BooleanField(default=False, verbose_name="Öffentlich"), |
| 32 | + ), |
| 33 | + migrations.AddField( |
| 34 | + model_name="person", |
| 35 | + name="published_date", |
| 36 | + field=models.DateTimeField( |
| 37 | + blank=True, null=True, verbose_name="Erstmals Veröffentlicht" |
| 38 | + ), |
| 39 | + ), |
| 40 | + migrations.AddField( |
| 41 | + model_name="person", |
| 42 | + name="republished_date", |
| 43 | + field=models.DateTimeField( |
| 44 | + blank=True, null=True, verbose_name="Letzte Veröffentlichung" |
| 45 | + ), |
| 46 | + ), |
| 47 | + migrations.AddField( |
| 48 | + model_name="person", |
| 49 | + name="uid", |
| 50 | + field=models.UUIDField( |
| 51 | + default=uuid.uuid4, editable=False, null=True, verbose_name="UID" |
| 52 | + ), |
| 53 | + ), |
| 54 | + migrations.RunPython( |
| 55 | + code=generate_unique_uid, reverse_code=migrations.RunPython.noop |
| 56 | + ), |
| 57 | + migrations.AlterField( |
| 58 | + model_name="person", |
| 59 | + name="uid", |
| 60 | + field=models.UUIDField( |
| 61 | + default=uuid.uuid4, editable=False, unique=True, verbose_name="UID" |
| 62 | + ), |
| 63 | + ), |
| 64 | + ] |
0 commit comments