import uuid import django.db.models.deletion from django.conf import settings from django.db import migrations, models class Migration(migrations.Migration): initial = True dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name="Topic", fields=[ ( "id", models.UUIDField( default=uuid.uuid4, editable=False, primary_key=True, serialize=False, ), ), ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), ("updated_at", models.DateTimeField(auto_now=True)), ("name", models.CharField(max_length=120)), ("slug", models.SlugField(max_length=140, unique=True)), ("description", models.TextField(blank=True)), ( "icon", models.CharField( blank=True, help_text="Icon identifier for the frontend.", max_length=64, ), ), ( "order", models.PositiveIntegerField( default=0, help_text="Sort position among siblings." ), ), ( "parent", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="children", to="taxonomy.topic", ), ), ], options={ "ordering": ["order", "name"], }, ), migrations.CreateModel( name="Tag", fields=[ ( "id", models.UUIDField( default=uuid.uuid4, editable=False, primary_key=True, serialize=False, ), ), ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), ("updated_at", models.DateTimeField(auto_now=True)), ("name", models.CharField(max_length=80)), ("slug", models.SlugField(max_length=100, unique=True)), ("description", models.TextField(blank=True)), ( "is_curated", models.BooleanField( default=False, help_text="Curated tags are protected from renaming/merging.", ), ), ("usage_count", models.PositiveIntegerField(db_index=True, default=0)), ( "created_by", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="+", to=settings.AUTH_USER_MODEL, ), ), ( "topic", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="tags", to="taxonomy.topic", ), ), ], options={ "ordering": ["-usage_count", "name"], }, ), migrations.AddIndex( model_name="topic", index=models.Index( fields=["parent", "order"], name="topic_parent_order_idx" ), ), migrations.AddConstraint( model_name="topic", constraint=models.CheckConstraint( condition=models.Q(("parent__isnull", True)) | ~models.Q(("parent", models.F("id"))), name="topic_not_own_parent", ), ), ]