# Generated by Django 4.0.6 on 2022-08-04 18:36

from django.db import migrations
from django.db.models import F, Q
from django.db.models.functions import Concat


def concat_codebaseresource_name_and_extension(apps, schema_editor):
    CodebaseResource = apps.get_model('scanpipe', 'CodebaseResource')
    qs = CodebaseResource.objects.filter(
        Q(extension__isnull=False)  # Has an "extension" value
        & ~Q(name__endswith=F("extension"))  # "name" do not ends with the "extension"
    )
    qs.update(name=Concat(F("name"), F("extension")))


class Migration(migrations.Migration):

    dependencies = [
        ('scanpipe', '0018_codebaseresource_tag'),
    ]

    operations = [
        migrations.RunPython(concat_codebaseresource_name_and_extension),
    ]
