# Generated by Django 3.0.5 on 2020-05-03 09:09

import os
import sys
import json
from django.db import migrations


def load_companies_data(apps, schema_editor):
    Company = apps.get_model("core", "Company")
    base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    fullpath = os.path.join(os.path.dirname(base_dir), 'resources/companies.json')

    with open(fullpath, encoding='utf-8') as cfile:
        companies = json.load(cfile)

        for company in companies:
            item, _ = Company.objects.get_or_create(
                index=int(company['index']),
                name=company['company']
            )
            item.save()


def reverse_func(apps, schema_editor):
    """Logic for migration fallback"""
    Company = apps.get_model("core", "Company")
    Company.objects.all().delete()


class Migration(migrations.Migration):

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

    operations = [
        migrations.RunPython(load_companies_data, reverse_func)
    ] if 'test' not in sys.argv[1:] else []

# Generated by Django 3.0.5 on 2020-05-03 09:09

import os
import sys
import json
from django.db import migrations


def load_companies_data(apps, schema_editor):
    Company = apps.get_model("core", "Company")
    base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    fullpath = os.path.join(os.path.dirname(base_dir), 'resources/companies.json')

    with open(fullpath, encoding='utf-8') as cfile:
        companies = json.load(cfile)

        for company in companies:
            item, _ = Company.objects.get_or_create(
                index=int(company['index']),
                name=company['company']
            )
            item.save()


def reverse_func(apps, schema_editor):
    """Logic for migration fallback"""
    Company = apps.get_model("core", "Company")
    Company.objects.all().delete()


class Migration(migrations.Migration):

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

    operations = [
        migrations.RunPython(load_companies_data, reverse_func)
    ] if 'test' not in sys.argv[1:] else []

# Generated by Django 3.0.5 on 2020-05-03 09:09 Logic for migration fallback