# Generated by Django 4.2.23 on 2025-10-13 04:22

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ("extracts", "0025_merge_20251013_0334"),
        ("analyzer", "0017_merge_20251013_0333"),
        ("annotations", "0045_merge_20251013_0334"),
    ]

    operations = [
        migrations.AddField(
            model_name="relationship",
            name="created_by_analysis",
            field=models.ForeignKey(
                blank=True,
                help_text="If set, this relationship is private to the analysis that created it",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="created_relationships",
                to="analyzer.analysis",
            ),
        ),
        migrations.AddField(
            model_name="relationship",
            name="created_by_extract",
            field=models.ForeignKey(
                blank=True,
                help_text="If set, this relationship is private to the extract that created it",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="created_relationships",
                to="extracts.extract",
            ),
        ),
        migrations.AddIndex(
            model_name="relationship",
            index=models.Index(
                fields=["analysis"], name="annotations_analysi_162b7c_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="relationship",
            index=models.Index(
                fields=["created_by_analysis"], name="annotations_created_94b87e_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="relationship",
            index=models.Index(
                fields=["created_by_extract"], name="annotations_created_9b4ca5_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="relationship",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("created_by_analysis__isnull", True),
                    ("created_by_extract__isnull", True),
                    _connector="OR",
                ),
                name="relationship_created_by_only_one_source",
                violation_error_message="A relationship cannot be created by both an analysis and an extract",
            ),
        ),
    ]
