# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2019-02-28 20:21
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('users', '0036_merge_20190228_1458'),
    ]

    operations = [
        migrations.AddField(
            model_name='person',
            name='address_line_1',
            field=models.CharField(blank=True, max_length=80),
        ),
        migrations.AddField(
            model_name='person',
            name='address_line_2',
            field=models.CharField(blank=True, max_length=80),
        ),
        migrations.AddField(
            model_name='person',
            name='address_line_3',
            field=models.CharField(blank=True, max_length=80),
        ),

        migrations.RunSQL(
            # Merged old addresses Before we dump them
            [(""" 
                UPDATE users_person
                    SET 
                        address_line_1 = (
                            SELECT
                                CASE
                                    WHEN street_number > 0 AND street_name <> ''
                                        THEN concat(street_number, ' ', street_name)
                                    WHEN street_number > 0
                                        THEN concat(street_number)
                                    WHEN street_name <> ''
                                        THEN street_name
                                    ELSE ''
                                END
                        ),
                        address_line_2 = (
                            SELECT
                                CASE
                                    WHEN apartment_number <> ''
                                        THEN concat('# ', apartment_number)
                                    ELSE ''
                                END
                        )
            """)]
        ),

        migrations.RemoveField(
            model_name='person',
            name='apartment_number',
        ),
        migrations.RemoveField(
            model_name='person',
            name='street_name',
        ),
        migrations.RemoveField(
            model_name='person',
            name='street_number',
        ),

    ]
