# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-05-17 22:46
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    dependencies = [
        ("base", "0092_locale_db_collation"),
    ]

    operations = [
        migrations.AddField(
            model_name="translationmemoryentry",
            name="project",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="memory_entries",
                to="base.Project",
            ),
        ),
        migrations.AlterField(
            model_name="translationmemoryentry",
            name="entity",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="memory_entries",
                to="base.Entity",
            ),
        ),
        # Assign projects to existing TM entries in raw SQL because of a lot better performance.
        migrations.RunSQL(
            """
            WITH t AS (SELECT tme.id as tme_id, p.id as project_id FROM base_translationmemoryentry tme JOIN base_entity e ON (
              tme.entity_id=e.id
            ) JOIN base_resource r ON (
              e.resource_id=r.id
            ) JOIN base_project p ON (
              r.project_id=p.id
            ))
            UPDATE base_translationmemoryentry SET project_id=t.project_id FROM t WHERE id=t.tme_id
            """,
            """
            UPDATE base_translationmemoryentry SET project_id=NULL WHERE project_id IS NOT NULL
            """,
        ),
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-05-17 22:46
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    dependencies = [
        ("base", "0092_locale_db_collation"),
    ]

    operations = [
        migrations.AddField(
            model_name="translationmemoryentry",
            name="project",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="memory_entries",
                to="base.Project",
            ),
        ),
        migrations.AlterField(
            model_name="translationmemoryentry",
            name="entity",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="memory_entries",
                to="base.Entity",
            ),
        ),
        # Assign projects to existing TM entries in raw SQL because of a lot better performance.
        migrations.RunSQL(
            """
            WITH t AS (SELECT tme.id as tme_id, p.id as project_id FROM base_translationmemoryentry tme JOIN base_entity e ON (
              tme.entity_id=e.id
            ) JOIN base_resource r ON (
              e.resource_id=r.id
            ) JOIN base_project p ON (
              r.project_id=p.id
            ))
            UPDATE base_translationmemoryentry SET project_id=t.project_id FROM t WHERE id=t.tme_id
            """,
            """
            UPDATE base_translationmemoryentry SET project_id=NULL WHERE project_id IS NOT NULL
            """,
        ),
    ]

# -*- coding: utf-8 -*- # Generated by Django 1.10.7 on 2017-05-17 22:46 # Assign projects to existing TM entries in raw SQL because of a lot better performance. WITH t AS (SELECT tme.id as tme_id, p.id as project_id FROM base_translationmemoryentry tme JOIN base_entity e ON (               tme.entity_id=e.id             ) JOIN base_resource r ON (               e.resource_id=r.id             ) JOIN base_project p ON (               r.project_id=p.id             ))             UPDATE base_translationmemoryentry SET project_id=t.project_id FROM t WHERE id=t.tme_id UPDATE base_translationmemoryentry SET project_id=NULL WHERE project_id IS NOT NULL