Skip to content

Instantly share code, notes, and snippets.

@lockie
Last active January 14, 2018 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lockie/99c0869dae93025a4205eb6b040adeb7 to your computer and use it in GitHub Desktop.
Save lockie/99c0869dae93025a4205eb6b040adeb7 to your computer and use it in GitHub Desktop.
A Django migration to add PostgreSQL trigram search, aka pg_trgm
# -*- coding: utf-8 -*-
# XXX this is actually useful for very special use cases, e.g. misspel suggestions:
# https://www.postgresql.org/docs/9.6/static/pgtrgm.html#AEN180626
from __future__ import unicode_literals
from django.db import migrations
from django.contrib.postgres.operations import TrigramExtension
class Migration(migrations.Migration):
operations = [
TrigramExtension(),
migrations.RunSQL(
'create index trgm_idx on polls_poll '
'using gin (text gin_trgm_ops);',
reverse_sql='drop index trgm_idx;'
),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment