chore: replace datalayer ids with uuids
This commit is contained in:
parent
d5b1821117
commit
6b7efda37a
2 changed files with 36 additions and 1 deletions
34
umap/migrations/0018_datalayer_uuid.py
Normal file
34
umap/migrations/0018_datalayer_uuid.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# Generated by Django 4.2.8 on 2024-02-19 17:40
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def gen_uuid(apps, schema_editor):
|
||||||
|
DataLayer = apps.get_model("umap", "DataLayer")
|
||||||
|
for row in DataLayer.objects.all():
|
||||||
|
row.uuid = uuid.uuid4()
|
||||||
|
row.save(update_fields=["uuid"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("umap", "0017_migrate_to_openstreetmap_oauth2"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="datalayer",
|
||||||
|
name="uuid",
|
||||||
|
field=models.UUIDField(default=uuid.uuid4, editable=False, null=True),
|
||||||
|
),
|
||||||
|
migrations.RunPython(gen_uuid, reverse_code=migrations.RunPython.noop),
|
||||||
|
migrations.AlterField("datalayer", name="id", field=models.CharField(max_length=100)),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="datalayer",
|
||||||
|
name="uuid",
|
||||||
|
field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True, primary_key=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -373,7 +374,7 @@ class DataLayer(NamedModel):
|
||||||
(EDITORS, _("Editors only")),
|
(EDITORS, _("Editors only")),
|
||||||
(OWNER, _("Owner only")),
|
(OWNER, _("Owner only")),
|
||||||
)
|
)
|
||||||
|
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
|
||||||
map = models.ForeignKey(Map, on_delete=models.CASCADE)
|
map = models.ForeignKey(Map, on_delete=models.CASCADE)
|
||||||
description = models.TextField(blank=True, null=True, verbose_name=_("description"))
|
description = models.TextField(blank=True, null=True, verbose_name=_("description"))
|
||||||
geojson = models.FileField(upload_to=upload_to, blank=True, null=True)
|
geojson = models.FileField(upload_to=upload_to, blank=True, null=True)
|
||||||
|
|
Loading…
Reference in a new issue