# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-03-12 08:48
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    replaces = [('aims', '0055_add_budget_usd_value'), ('aims', '0056_currency_conversions_unique'), ('aims', '0057_auto_20180312_1353'), ('aims', '0058_auto_20180312_1513'), ('aims', '0059_auto_20180312_1540'), ('aims', '0060_auto_20180312_1700'), ('aims', '0061_auto_20180312_1702')]

    dependencies = [
        ('aims', '0053_viewed_model_indexes_concurrency'),
    ]

    operations = [
        # Enforce uniqueness for CurrencyExchangeRate combinations
        migrations.RunSQL(
            sql='\n            WITH pre AS (SELECT *, row_number() OVER (PARTITION BY base_currency_id, currency_id, date)\n            FROM aims_currency_exchange_rate)\n            DELETE FROM aims_currency_exchange_rate\n            WHERE id IN (SELECT id FROM pre WHERE row_number != 1);\n            ',
        ),
        migrations.AlterUniqueTogether(
            name='currencyexchangerate',
            unique_together=set([('base_currency', 'currency', 'date')]),
        ),
        migrations.CreateModel(
            name='BudgetExchangeRate',
            fields=[
                ('budget', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='aims.Budget')),
                ('exchangerate', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='aims.CurrencyExchangeRate')),
            ],
        ),
        migrations.CreateModel(
            name='TransactionExchangeRate',
            fields=[
                ('transaction', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='aims.Transaction')),
                ('exchangerate', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='aims.CurrencyExchangeRate')),
            ],
        ),
        migrations.AddField(
            model_name='transaction',
            name='usd_value',
            field=models.DecimalField(blank=True, decimal_places=2, max_digits=15, null=True),
        ),
        migrations.AddField(
            model_name='budget',
            name='usd_value',
            field=models.DecimalField(blank=True, decimal_places=2, max_digits=15, null=True),
        ),
    ]
