# Generated by Django 3.1.14 on 2022-03-11 15:06

from django.conf import settings
from django.db import migrations


def forward(apps, schema_editor):
    with schema_editor.connection.cursor() as cursor:
        cursor.execute(
            f"SELECT 1 FROM information_schema.columns WHERE table_name='infrastructure_infrastructure' AND column_name='published'"
        )
        if cursor.fetchone():
            for lang in settings.MODELTRANSLATION_LANGUAGES:
                cursor.execute(
                    f"SELECT 1 FROM information_schema.columns WHERE table_name='infrastructure_infrastructure' AND column_name='published_{lang}'"
                )
                if not cursor.fetchone():
                    cursor.execute(
                        f"ALTER TABLE infrastructure_infrastructure ADD published_{lang} Boolean DEFAULT True;"
                    )


def backward(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('infrastructure', '0027_infrastructure_accessibility'),
    ]

    operations = [
        migrations.RunPython(forward, backward),
    ]

Add migration fix published language
Add migration fix published language
