# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-05-23 20:12
from __future__ import unicode_literals

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

def migrate_data_sources(apps, schema_editor):
    """This is an irreversible migration"""
    DataSource = apps.get_model('data', 'DataSource')
    # NOTE TO SELF: Do not manually set id in the future because this doesn't
    #               increment the database's autoincrement field.
    DataSource.objects.update_or_create(id=1, defaults={
        'source': 'self',
        'model': 'self',
        'field': 'self'
    })

class Migration(migrations.Migration):

    dependencies = [
        ('data', '0018_auto_20170513_0710'),
    ]

    operations = [
        migrations.CreateModel(
            name='DataSource',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('source', models.TextField()),
                ('source_display', models.TextField(blank=True, null=True)),
                ('source_icon', models.TextField(blank=True, null=True)),
                ('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.AlterField(
            model_name='customfield',
            name='type',
            field=models.TextField(choices=[(b'model', b'model'), (b'string', b'string'), (b'text', b'text'), (b'date', b'date'), (b'money', b'money'), (b'image', b'image'), (b'number', b'number'), (b'choice', b'choice')]),
        ),
        migrations.AlterUniqueTogether(
            name='datasource',
            unique_together=set([('source', 'model', 'field')]),
        ),
        # Must create the default DataSource object before adding the
        # not-nullable reference to CustomField
        migrations.RunPython(migrate_data_sources),
        migrations.AddField(
            model_name='customfield',
            name='source',
            field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='custom_fields', to='data.DataSource'),
        ),
    ]
