# Generated by Django 3.2.5 on 2022-10-14 10:50

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



# RUN ON MIGRATIONS  -- remigrate if work_model is updated 


def print_migration_message(message):
    BOLD = "\033[1m"
    GREEN = "\033[92m"
    RESET = "\033[0m"
    return f"{BOLD}{GREEN}{message}{RESET}"



def update_flow_model(apps, schema_editor):
    flowmodel = apps.get_model("finflo.Flowmodel")
    try:
        a = settings.FINFLO['WORK_MODEL']
        db_alias = schema_editor.connection.alias
        for model in a:
            print(print_migration_message("Applying Finflo migrations..."))
            flowmodel.objects.using(db_alias).update_or_create(description = model.lower())
    except:
        raise LookupError("Couldn't find work_model in settings.py check documentation")





    
class Migration(migrations.Migration):

    dependencies = [
        ('finflo', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(update_flow_model),
    ]