Add mgmt command to create trigram indexes.
This commit is contained in:
parent
ddfbe2646e
commit
e8e5b6e85a
0
chaloBEST/mumbai/management/__init__.py
Normal file
0
chaloBEST/mumbai/management/__init__.py
Normal file
0
chaloBEST/mumbai/management/commands/__init__.py
Normal file
0
chaloBEST/mumbai/management/commands/__init__.py
Normal file
18
chaloBEST/mumbai/management/commands/trgmidx.py
Normal file
18
chaloBEST/mumbai/management/commands/trgmidx.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import connection
|
||||
from mumbai import models
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Instantiates the pg_trgm indexes"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
cursor = connection.cursor()
|
||||
for name, model in models:
|
||||
if not hasattr(model, "objects") or \
|
||||
not isinstance(model.objects, model.TrigramSearchManager):
|
||||
continue
|
||||
table = model._meta.db_table
|
||||
for column in model.objects.trigram_columns:
|
||||
cursor.execute("""
|
||||
CREATE INDEX %s_%s_trgm_idx ON %s USING gin (%s gin_trgm_ops);""" % (
|
||||
table, column, table, column))
|
Loading…
Reference in New Issue
Block a user