# Generated by Django 4.2.24

from django.db import migrations, models


class Migration(migrations.Migration):
    """
    Add is_personal field to Corpus model with unique constraint
    ensuring one personal corpus per user.

    This migration:
    1. Adds the is_personal boolean field (default=False)
    2. Adds an index for efficient (creator, is_personal) lookups
    3. Adds a unique constraint ensuring at most one personal corpus per user
    """

    dependencies = [
        (
            "corpuses",
            "0036_alter_corpusquerygroupobjectpermission_unique_together_and_more",
        ),
    ]

    operations = [
        # Add the is_personal field
        migrations.AddField(
            model_name="corpus",
            name="is_personal",
            field=models.BooleanField(
                default=False,
                help_text="True if this is the user's personal 'My Documents' corpus",
            ),
        ),
        # Add index for efficient lookups
        migrations.AddIndex(
            model_name="corpus",
            index=models.Index(
                fields=["creator", "is_personal"],
                name="corpuses_co_creator_0e8c8f_idx",
            ),
        ),
        # Add unique constraint for one personal corpus per user
        migrations.AddConstraint(
            model_name="corpus",
            constraint=models.UniqueConstraint(
                condition=models.Q(("is_personal", True)),
                fields=("creator",),
                name="one_personal_corpus_per_user",
            ),
        ),
    ]
