# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-15 14:42
from __future__ import unicode_literals

from django.db import migrations


def conditionally_remove_unit_created_by(apps, schema_editor):
    Unit = apps.get_model("pootle_store.Unit")
    connection = schema_editor.connection
    cursor = connection.cursor()
    fields = connection.introspection.get_table_description(cursor,
                                                            Unit._meta.db_table)

    # Since we have no real way of controlling if when this is run the field
    # actually exists, we need to test the field exists.
    if 'created_by_id' in [field.name for field in fields]:
        schema_editor.remove_field(Unit, Unit._meta.get_field('created_by'))


class Migration(migrations.Migration):

    dependencies = [
        ('pootle_store', '0032_qc_tablename'),
    ]

    operations = [
        migrations.RunPython(conditionally_remove_unit_created_by),
    ]
