# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-01-07 13:01
from __future__ import unicode_literals

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

from djorm_pgfulltext.fields import VectorField

# Add search indexes for "text" and "iati_identifier"
class Migration(migrations.Migration):

    dependencies = [
        ('iati', '0023_auto_20160325_0914'),
    ]

    def create_search_indexes(apps, schema_editor):
        def create_search_index(column_name):
            schema_editor.execute("CREATE INDEX {table_name}_{column_name}_simple_tsv ON {table_name} USING gin({column_name});".format(table_name='iati_activitysearch', column_name=column_name))

        for column in ['iati_identifier', 'text']:
            create_search_index(column)

    def drop_search_indexes(apps, schema_editor):
        def drop_search_index(column_name):
            schema_editor.execute("DROP INDEX {table_name}_{column_name}_simple_tsv ;".format(
                table_name='iati_activitysearch',
                column_name=column_name,
            ))

        for column in ['iati_identifier', 'text']:
            drop_search_index(column)

    operations = [
        migrations.RunPython(create_search_indexes, drop_search_indexes),
    ]


add full text indexes to iati_identifier and text fields