# -*- coding: utf-8 -*-
# Generated by Django 1.11.25 on 2020-06-16 12:02
from __future__ import unicode_literals

from django.db import migrations


def add_checksum_algorithms(apps, schema_editor):
    """
    Add hash algorithms:
    - SHA1
    - SHA256
    - MD5
    """
    ChecksumAlgorithms = apps.get_model("emgapi", "ChecksumAlgorithm")
    for alg in ["SHA1", "SHA256", "MD5"]:
        ChecksumAlgorithms.objects.get_or_create(name=alg)


def remove_checksum_algorithms(apps, schema_editor):
    """
    Remove hash algorithms:
    - SHA1
    - SHA256
    - MD5
    """
    ChecksumAlgorithms = apps.get_model("emgapi", "ChecksumAlgorithm")
    for alg in ["SHA1", "SHA256", "MD5"]:
        try:
            ChecksumAlgorithms.objects.get(name=alg).delete()
        except ChecksumAlgorithms.DoesNotExist:
            pass

class Migration(migrations.Migration):

    dependencies = [
        ('emgapi', '0027_auto_20200706_1823'),
    ]

    operations = [
        migrations.RunPython(add_checksum_algorithms, reverse_code=remove_checksum_algorithms)
    ]
