# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-20 19:27
from __future__ import unicode_literals

from django.db import migrations

import os

ENVS = ['SITE_NAME',
        'SITE_DOMAIN',
        'CLIENT_ID',
        'SECRET',
        'CALENDAR_NAME',
        'CALENDAR_SLUG',
       ]

missing_env = 0

for ENV in ENVS:
    try:
        os.environ[ENV]
    except KeyError:
        print("Please set the environment variable {}".format(ENV))
        missing_env = 1

    class Migration(migrations.Migration):
    
        if not missing_env:
            dependencies = [
                ('laundryapp', '0001_initial'),
                ('sites', '__first__'),
                ('socialaccount', '__first__'),
                ('schedule', '__first__'),
            ]
    
            operations = [
                migrations.RunSQL([("INSERT INTO django_site (name, domain) VALUES (%s, %s);",
                                    [ os.environ['SITE_NAME'], os.environ['SITE_DOMAIN'] ])]),
                migrations.RunSQL([ ("INSERT INTO socialaccount_socialapp (provider, name, client_id, key, secret) VALUES (%s, %s, %s, %s, %s);",
                                    [ 'facebook', 'Facebook', os.environ['CLIENT_ID'], '', os.environ['SECRET'] ])]),
                migrations.RunSQL([ ("INSERT INTO socialaccount_socialapp_sites (socialapp_id, site_id) VALUES (%s, %s);",
                                    [ '1', '1' ]) ]),
                migrations.RunSQL([ ("INSERT INTO auth_group (name) VALUES (%s);",
                                    [ 'laundryapp' ]) ]),
                migrations.RunSQL([ ("INSERT INTO schedule_calendar (name, slug) VALUES (%s, %s);",
                                    [ os.environ['CALENDAR_NAME'], os.environ['CALENDAR_SLUG'] ]) ]),
            ]

