# Generated by Django 3.1.7 on 2021-10-12 10:39
import os

from django.db import connection, migrations


def load_triggers(apps, schema_editor):
    file_names = [
        "triggers_entity.sql",
        "triggers_collection.sql",
        "triggers_data.sql",
        "utils.sql",
    ]
    with connection.cursor() as c:
        for file_name in file_names:
            file_path = os.path.join(os.path.dirname(__file__), file_name)
            with open(file_path) as fh:
                sql_statement = fh.read()
            c.execute(sql_statement)


class Migration(migrations.Migration):
    dependencies = [("flow", "0027_worker_private_key_worker_public_key")]

    operations = [
        migrations.RunPython(load_triggers),
        migrations.RunSQL("UPDATE flow_collection SET id=id;"),
        migrations.RunSQL("UPDATE flow_entity SET id=id;"),
        migrations.RunSQL("UPDATE flow_data SET id=id;"),
    ]
