Last active
January 14, 2018 11:45
-
-
Save lockie/99c0869dae93025a4205eb6b040adeb7 to your computer and use it in GitHub Desktop.
A Django migration to add PostgreSQL trigram search, aka pg_trgm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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