# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-05-25 22:55
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

def migrate_custom_data(apps, schema_editor):
    """This is an irreversible migration"""
    CustomData = apps.get_model('data', 'CustomData')
    CustomData.objects.all().delete()

class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('users', '0012_auto_20170513_0710'),
        ('data', '0022_schema_auto_20170524_2049'),
    ]

    operations = [
        migrations.RunPython(migrate_custom_data),
        migrations.CreateModel(
            name='CustomFieldSource',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('account', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='custom_field_sources', to='users.Account')),
                ('field', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='custom_field_sources', to='data.CustomField')),
                ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='custom_field_sources', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='DataSourceOption',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('model', models.TextField()),
                ('model_display', models.TextField(blank=True, null=True)),
                ('model_icon', models.TextField(blank=True, null=True)),
                ('field', models.TextField()),
                ('field_display', models.TextField(blank=True, null=True)),
                ('field_icon', models.TextField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.RenameModel(
            old_name='APIIntegration',
            new_name='DataSource',
        ),
        migrations.AlterUniqueTogether(
            name='apiintegrationsource',
            unique_together=set([]),
        ),
        migrations.RemoveField(
            model_name='apiintegrationsource',
            name='integration',
        ),
        migrations.AlterUniqueTogether(
            name='customfieldintegration',
            unique_together=set([]),
        ),
        migrations.RemoveField(
            model_name='customfieldintegration',
            name='account',
        ),
        migrations.RemoveField(
            model_name='customfieldintegration',
            name='field',
        ),
        migrations.RemoveField(
            model_name='customfieldintegration',
            name='integration',
        ),
        migrations.RemoveField(
            model_name='customfieldintegration',
            name='owner',
        ),
        migrations.AlterField(
            model_name='customdata',
            name='field',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='custom_data', to='data.CustomFieldSource'),
        ),
        migrations.DeleteModel(
            name='APIIntegrationSource',
        ),
        migrations.DeleteModel(
            name='CustomFieldIntegration',
        ),
        migrations.AddField(
            model_name='datasourceoption',
            name='source',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='data_source_options', to='data.DataSource'),
        ),
        migrations.AddField(
            model_name='customfieldsource',
            name='source',
            field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='custom_field_sources', to='data.DataSource'),
        ),
        migrations.AddField(
            model_name='customfieldsource',
            name='source_option',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='custom_field_sources', to='data.DataSourceOption'),
        ),
        migrations.AlterUniqueTogether(
            name='datasourceoption',
            unique_together=set([('source', 'model', 'field')]),
        ),
        migrations.AlterUniqueTogether(
            name='customfieldsource',
            unique_together=set([('account', 'field', 'source')]),
        ),
    ]
