Skip to content

Commit

Permalink
add custom migration
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Jul 22, 2021
1 parent 54008e3 commit 7de89b2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/grants/migrations/0121_auto_20210722_0649.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.2.24 on 2021-07-22 06:49

import django.contrib.postgres.indexes
import django.contrib.postgres.search
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('grants', '0120_auto_20210622_1021'),
]

operations = [
migrations.AddField(
model_name='grant',
name='vector_column',
field=django.contrib.postgres.search.SearchVectorField(null=True),
),
migrations.AddIndex(
model_name='grant',
index=django.contrib.postgres.indexes.GinIndex(fields=['vector_column'], name='grants_gran_vector__534e95_gin'),
),
]
31 changes: 31 additions & 0 deletions app/grants/migrations/0122_create_trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 2.2.24 on 2021-07-22 06:51

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('grants', '0121_auto_20210722_0649'),
]

operations = [
migrations.RunSQL(
sql='''
CREATE TRIGGER vector_column_trigger
BEFORE INSERT OR UPDATE OF title, description, vector_column
ON grants_grant
FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(
vector_column, 'pg_catalog.english', title, description
);
UPDATE grants_grant SET vector_column = NULL;
''',

reverse_sql = '''
DROP TRIGGER IF EXISTS vector_column_trigger
ON grants_grant;
'''
),
]

0 comments on commit 7de89b2

Please sign in to comment.