from __future__ import unicode_literals

from django.db import migrations

from ..models import IndexEntry


table = IndexEntry._meta.db_table


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('wagtail_pgsearchbackend', '0001_initial'),
    ]

    operations = [
        migrations.RunSQL(
            'CREATE INDEX IF NOT EXISTS {0}_body_search ON {0} '
            'USING GIN(body_search);'.format(table),
            'DROP INDEX IF EXISTS {}_body_search;'.format(table),
        ),
    ]

from __future__ import unicode_literals

from django.db import migrations

from ..models import IndexEntry


table = IndexEntry._meta.db_table


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('wagtail_pgsearchbackend', '0001_initial'),
    ]

    operations = [
        migrations.RunSQL(
            'CREATE INDEX {0}_body_search ON {0} '
            'USING GIN(body_search);'.format(table),
            'DROP INDEX IF EXISTS {}_body_search;'.format(table),
        ),
    ]

Fix migration for Postgres < 9.5
Fix migration for Postgres < 9.5

  from __future__ import unicode_literals
  
  from django.db import migrations
  
  from ..models import IndexEntry
  
  
  table = IndexEntry._meta.db_table
  
  
  class Migration(migrations.Migration):
  
      initial = True
  
      dependencies = [
          ('wagtail_pgsearchbackend', '0001_initial'),
      ]
  
      operations = [
          migrations.RunSQL(
-             'CREATE INDEX IF NOT EXISTS {0}_body_search ON {0} '
+             'CREATE INDEX {0}_body_search ON {0} '
              'USING GIN(body_search);'.format(table),
              'DROP INDEX IF EXISTS {}_body_search;'.format(table),
          ),
      ]
  
Fix migration for Postgres < 9.5
## Code Before:
from __future__ import unicode_literals

from django.db import migrations

from ..models import IndexEntry


table = IndexEntry._meta.db_table


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('wagtail_pgsearchbackend', '0001_initial'),
    ]

    operations = [
        migrations.RunSQL(
            'CREATE INDEX IF NOT EXISTS {0}_body_search ON {0} '
            'USING GIN(body_search);'.format(table),
            'DROP INDEX IF EXISTS {}_body_search;'.format(table),
        ),
    ]

## Instruction:
Fix migration for Postgres < 9.5
## Code After:
from __future__ import unicode_literals

from django.db import migrations

from ..models import IndexEntry


table = IndexEntry._meta.db_table


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('wagtail_pgsearchbackend', '0001_initial'),
    ]

    operations = [
        migrations.RunSQL(
            'CREATE INDEX {0}_body_search ON {0} '
            'USING GIN(body_search);'.format(table),
            'DROP INDEX IF EXISTS {}_body_search;'.format(table),
        ),
    ]
