# Generated by Django 2.2.10 on 2020-04-20 15:24

from django.db import migrations


# This translate the specie scientific name with DAD-IS common name
# at the moment, Rainbow trout hasn't an entry into DAD-IS
species_list = [
    ('Equus asinus', 'Ass'),
    ('Bos taurus', 'Cattle'),
    ('Gallus gallus', 'Chicken'),
    ('Cervidae', 'Deer'),
    ('Anas platyrhynchos', 'Duck (domestic)'),
    ('Capra hircus', 'Goat'),
    ('Anser anser', 'Goose (domestic)'),
    ('Equus caballus', 'Horse'),
    ('Sus scrofa', 'Pig'),
    ('Oryctolagus cuniculus', 'Rabbit'),
    ('Ovis aries', 'Sheep'),
    ('Meleagris gallopavo', 'Turkey'),
    ('Oncorhynchus mykiss', 'Rainbow trout'),
    ('Canis lupus familiaris', 'Dog'),
]


def forwards_func(apps, schema_editor):
    # We get the model from the versioned app registry;
    # if we directly import it, it'll be the wrong version
    Species2CommonName = apps.get_model(
        "backend",
        "Species2CommonName")

    db_alias = schema_editor.connection.alias

    Species2CommonName.objects.using(db_alias).bulk_create([
        Species2CommonName(
            scientific_name=scientific_name,
            common_name=common_name)
        for scientific_name, common_name in species_list
    ])


def reverse_func(apps, schema_editor):
    # We get the model from the versioned app registry;
    # if we directly import it, it'll be the wrong version
    Species2CommonName = apps.get_model(
        "backend",
        "Species2CommonName")

    db_alias = schema_editor.connection.alias

    # delete all the objects in the Species2CommonName table
    Species2CommonName.objects.using(db_alias).delete()


class Migration(migrations.Migration):

    dependencies = [
        ('backend', '0003_dadislink_species2commonname'),
    ]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]
