# Generated by Django 5.1 on 2024-09-18 21:20

from django.db import migrations, models
from django.db.models import Case, When, Value, CharField

def forward_func(apps, _):
    Item = apps.get_model('app', 'Item')

    # Define the cases for updating the 'source' field
    source_cases = [
        When(media_type__in=["tv", "season", "episode", "movie"], then=Value("tmdb")),
        When(media_type__in=["manga", "anime"], then=Value("mal")),
        When(media_type="game", then=Value("igdb")),
    ]

    # Perform the bulk update
    Item.objects.update(
        source=Case(
            *source_cases,
            default=Value(""),
            output_field=CharField()
        )
    )

def reverse_func(apps, _):
    Item = apps.get_model('app', 'Item')

    # Perform the bulk update
    Item.objects.update(source="")

class Migration(migrations.Migration):

    dependencies = [
        ('app', '0021_alter_item_media_type'),
    ]

    operations = [
        migrations.AddField(
            model_name='item',
            name='source',
            field=models.CharField(default='', max_length=255),
        ),
        migrations.RunPython(forward_func, reverse_func),
    ]
