diff --git a/backend/data_export/migrations/0001_initial.py b/backend/data_export/migrations/0001_initial.py new file mode 100644 index 00000000..8dc9c193 --- /dev/null +++ b/backend/data_export/migrations/0001_initial.py @@ -0,0 +1,66 @@ +# Generated by Django 4.0.2 on 2022-05-12 02:27 + +from django.db import migrations + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("examples", "0006_alter_example_upload_name"), + ("labels", "0012_add_uuid_field"), + ] + + operations = [ + migrations.CreateModel( + name="ExportedCategory", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("labels.category",), + ), + migrations.CreateModel( + name="ExportedExample", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("examples.example",), + ), + migrations.CreateModel( + name="ExportedRelation", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("labels.relation",), + ), + migrations.CreateModel( + name="ExportedSpan", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("labels.span",), + ), + migrations.CreateModel( + name="ExportedText", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("labels.textlabel",), + ), + ] diff --git a/backend/labels/migrations/0012_add_uuid_field.py b/backend/labels/migrations/0012_add_uuid_field.py new file mode 100644 index 00000000..6659fa13 --- /dev/null +++ b/backend/labels/migrations/0012_add_uuid_field.py @@ -0,0 +1,34 @@ +# Generated by Django 4.0.2 on 2022-05-12 02:27 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ("labels", "0011_remove_relation_direction"), + ] + + operations = [ + migrations.AddField( + model_name="category", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, null=True), + ), + migrations.AddField( + model_name="relation", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, null=True), + ), + migrations.AddField( + model_name="span", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, null=True), + ), + migrations.AddField( + model_name="textlabel", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, null=True), + ), + ] diff --git a/backend/labels/migrations/0013_populate_uuid_values.py b/backend/labels/migrations/0013_populate_uuid_values.py new file mode 100644 index 00000000..30253a42 --- /dev/null +++ b/backend/labels/migrations/0013_populate_uuid_values.py @@ -0,0 +1,27 @@ +# Generated by Django 4.0.2 on 2022-05-12 02:28 + +from django.db import migrations + +import uuid + + +def gen_uuid(apps, schema_editor): + Category = apps.get_model("labels", "Category") + Span = apps.get_model("labels", "Span") + Relation = apps.get_model("labels", "Relation") + TextLabel = apps.get_model("labels", "TextLabel") + for label in [Category, Span, Relation, TextLabel]: + for row in label.objects.all(): + row.uuid = uuid.uuid4() + row.save(update_fields=["uuid"]) + + +class Migration(migrations.Migration): + + dependencies = [ + ("labels", "0012_add_uuid_field"), + ] + + operations = [ + migrations.RunPython(gen_uuid, reverse_code=migrations.RunPython.noop), + ] diff --git a/backend/labels/migrations/0014_remove_uuid_null.py b/backend/labels/migrations/0014_remove_uuid_null.py new file mode 100644 index 00000000..17d5c05c --- /dev/null +++ b/backend/labels/migrations/0014_remove_uuid_null.py @@ -0,0 +1,33 @@ +import uuid + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("labels", "0013_populate_uuid_values"), + ] + + operations = [ + migrations.AlterField( + model_name="category", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, unique=True), + ), + migrations.AlterField( + model_name="relation", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, unique=True), + ), + migrations.AlterField( + model_name="span", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, unique=True), + ), + migrations.AlterField( + model_name="textlabel", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, unique=True), + ), + ] diff --git a/backend/labels/models.py b/backend/labels/models.py index 7fff6155..c07de8ff 100644 --- a/backend/labels/models.py +++ b/backend/labels/models.py @@ -1,3 +1,5 @@ +import uuid + from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.db import models @@ -16,6 +18,7 @@ from label_types.models import CategoryType, RelationType, SpanType class Label(models.Model): objects = LabelManager() + uuid = models.UUIDField(default=uuid.uuid4, unique=True) prob = models.FloatField(default=0.0) manual = models.BooleanField(default=False) user = models.ForeignKey(User, on_delete=models.CASCADE)