# SPDX-FileCopyrightText: 2025-present Tobias Kunze
# SPDX-License-Identifier: AGPL-3.0-only WITH LicenseRef-Pretalx-AGPL-3.0-Terms

# Generated by Django 5.1.7 on 2025-05-05 07:04

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


class Migration(migrations.Migration):

    dependencies = [
        ("submission", "0079_rename_public_tag_is_public"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        # Make the through model between speaker and submission explicit
        # https://docs.djangoproject.com/en/dev/howto/writing-migrations/#changing-a-manytomanyfield-to-use-a-through-model
        migrations.SeparateDatabaseAndState(
            database_operations=[
                migrations.RunSQL(
                    sql="ALTER TABLE submission_submission_speakers RENAME TO submission_speakerrole",
                    reverse_sql="ALTER TABLE submission_speakerrole RENAME TO submission_submission_speakers",
                ),
            ],
            state_operations=[
                migrations.CreateModel(
                    name="SpeakerRole",
                    fields=[
                        (
                            "id",
                            models.AutoField(
                                auto_created=True, primary_key=True, serialize=False
                            ),
                        ),
                        (
                            "submission",
                            models.ForeignKey(
                                on_delete=django.db.models.deletion.CASCADE,
                                related_name="speaker_roles",
                                to="submission.submission",
                            ),
                        ),
                        (
                            "user",
                            models.ForeignKey(
                                on_delete=django.db.models.deletion.CASCADE,
                                related_name="speaker_roles",
                                to=settings.AUTH_USER_MODEL,
                            ),
                        ),
                    ],
                    options={
                        "unique_together": {("submission", "user")},
                    },
                ),
                migrations.AlterField(
                    model_name="submission",
                    name="speakers",
                    field=models.ManyToManyField(
                        related_name="submissions",
                        through="submission.SpeakerRole",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
    ]
