# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2019-05-09 17:13
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    dependencies = [
        ('dataentry', '0093_auto_20190507_1241'),
    ]

    operations = [
        migrations.CreateModel(
            name='FormCategory',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=126)),
                ('xorder', models.PositiveIntegerField(blank=True, null=True)),
            ],
        ),
        migrations.AddField(
            model_name='formcategory',
            name='category',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dataentry.Category'),
        ),
        migrations.AddField(
            model_name='formcategory',
            name='form',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dataentry.Form'),
        ),
        migrations.AddField(
            model_name='formcategory',
            name='storage',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='dataentry.Storage'),
        ),
        migrations.RunSQL("insert into dataentry_formcategory (name, xorder, category_id, form_id, storage_id) select name, dataentry_category.order, id, form_id, null from dataentry_category;"),
        migrations.RunSQL("update dataentry_formcategory set storage_id = (select storage_id from dataentry_cardstorage where form_id=dataentry_formcategory.form_id and category_id=dataentry_formcategory.category_id);"),
        migrations.RenameField(
            model_name='formcategory',
            old_name='xorder',
            new_name='order',
        ),         
        migrations.RemoveField(
            model_name='cardstorage',
            name='category',
        ),
        migrations.RemoveField(
            model_name='cardstorage',
            name='storage',
        ),
        migrations.RenameField(
            model_name='category',
            old_name='name',
            new_name='description',
        ),
        migrations.RemoveField(
            model_name='category',
            name='form',
        ),
        migrations.RemoveField(
            model_name='category',
            name='order',
        ),
        migrations.DeleteModel(
            name='CardStorage',
        ),
        
    ]
