# Generated by Django 5.2.11 on 2026-03-12 04:22

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


def clear_splice_entries(apps, schema_editor):
    """Clear existing splice plan entries since the FK target is changing from FrontPort to FiberStrand."""
    SplicePlanEntry = apps.get_model("netbox_fms", "SplicePlanEntry")
    SplicePlanEntry.objects.all().delete()


class Migration(migrations.Migration):
    dependencies = [
        ("dcim", "0226_modulebay_rebuild_tree"),
        ("netbox_fms", "0002_buffertube_stripe_color_and_more"),
    ]

    operations = [
        migrations.AddField(
            model_name="fiberstrand",
            name="front_port",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="fiber_strands",
                to="dcim.frontport",
            ),
        ),
        # Clear existing entries before changing FK target
        migrations.RunPython(clear_splice_entries, migrations.RunPython.noop),
        migrations.AlterField(
            model_name="spliceplanentry",
            name="fiber_a",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="splice_entries_a",
                to="netbox_fms.fiberstrand",
            ),
        ),
        migrations.AlterField(
            model_name="spliceplanentry",
            name="fiber_b",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="splice_entries_b",
                to="netbox_fms.fiberstrand",
            ),
        ),
    ]
