# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-05 20:36
from __future__ import unicode_literals

from django.conf import settings
import django.contrib.postgres.fields
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


# Remove segmentation tool setting from user profile and its history table.
forward = """
    SELECT drop_history_view_for_table('catmaid_userprofile'::regclass);
    SELECT disable_history_tracking_for_table('catmaid_userprofile'::regclass,
            get_history_table_name('catmaid_userprofile'::regclass));

    -- Remove column from userprofile table and its history table.
    ALTER TABLE catmaid_userprofile__history DROP COLUMN show_segmentation_tool;
    ALTER TABLE catmaid_userprofile DROP COLUMN show_segmentation_tool;

    SELECT enable_history_tracking_for_table('catmaid_userprofile'::regclass,
            get_history_table_name('catmaid_userprofile'::regclass), FALSE);
    SELECT create_history_view_for_table('catmaid_userprofile'::regclass);
"""

# Add segmentation tool setting to user profile and its history table.
backward = """
    SELECT drop_history_view_for_table('catmaid_userprofile'::regclass);
    SELECT disable_history_tracking_for_table('catmaid_userprofile'::regclass,
            get_history_table_name('catmaid_userprofile'::regclass));

    -- Add column from userprofile table and its history table.
    ALTER TABLE catmaid_userprofile ADD COLUMN show_segmentation_tool boolean NOT NULL DEFAULT FALSE;
    ALTER TABLE catmaid_userprofile__history ADD COLUMN show_segmentation_tool boolean;

    SELECT enable_history_tracking_for_table('catmaid_userprofile'::regclass,
            get_history_table_name('catmaid_userprofile'::regclass), FALSE);
    SELECT create_history_view_for_table('catmaid_userprofile'::regclass);
"""


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('catmaid', '0059_add_node_query_grid_cache'),
    ]

    operations = [
        migrations.RunSQL(forward, backward, [
            migrations.RemoveField(
                model_name='userprofile',
                name='show_segmentation_tool',
            ),
        ])
    ]
