# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2017-05-09 09:24
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('attempts', '0007_auto_20161004_0927'),
    ]

    operations = [
        migrations.AddField(
            model_name='attempt',
            name='submission_date',
            field=models.DateTimeField(null=True),
        ),
        migrations.AddField(
            model_name='historicalattempt',
            name='submission_date',
            field=models.DateTimeField(null=True),
        ),
        migrations.RunSQL(
            'UPDATE attempts_historicalattempt SET submission_date = history_date'
        ),
        migrations.RunSQL(
            '''UPDATE attempts_attempt
                  SET submission_date = subquery.submission_date
                 FROM (
                    SELECT user_id, part_id, max(history_date) AS submission_date
                      FROM attempts_historicalattempt
                     GROUP BY user_id, part_id
                 ) AS subquery
                WHERE attempts_attempt.user_id = subquery.user_id
                  AND attempts_attempt.part_id = subquery.part_id
            '''
        ),
        migrations.AlterField(
            model_name='attempt',
            name='submission_date',
            field=models.DateTimeField(auto_now=True),
        ),
        migrations.AlterField(
            model_name='historicalattempt',
            name='submission_date',
            field=models.DateTimeField(blank=True, editable=False),
        ),
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2017-05-09 09:24
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('attempts', '0007_auto_20161004_0927'),
    ]

    operations = [
        migrations.AddField(
            model_name='attempt',
            name='submission_date',
            field=models.DateTimeField(null=True),
        ),
        migrations.AddField(
            model_name='historicalattempt',
            name='submission_date',
            field=models.DateTimeField(null=True),
        ),
        migrations.RunSQL(
            'UPDATE attempts_historicalattempt SET submission_date = history_date'
        ),
        migrations.RunSQL(
            '''UPDATE attempts_attempt
                  SET submission_date = (
                     SELECT max(history_date)
                      FROM attempts_historicalattempt
                     WHERE attempts_attempt.user_id = user_id
                       AND attempts_attempt.part_id = part_id
                 )
            '''
        ),
        migrations.AlterField(
            model_name='attempt',
            name='submission_date',
            field=models.DateTimeField(auto_now=True),
        ),
        migrations.AlterField(
            model_name='historicalattempt',
            name='submission_date',
            field=models.DateTimeField(blank=True, editable=False),
        ),
    ]

Make migration SQLite compatible