Skip to content

Commit ac9554d

Browse files
feat: Add GIN index for name field
1 parent 01d5856 commit ac9554d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Generated by Django 4.2.25 on 2025-12-04 01:26
2+
3+
import django.contrib.postgres.indexes
4+
import django.db.models.functions.text
5+
from django.db import migrations
6+
7+
from shared.django_apps.migration_utils import RiskyAddIndex
8+
9+
10+
class Migration(migrations.Migration):
11+
"""
12+
BEGIN;
13+
--
14+
-- Create index repos_name_trgm_idx on OpClass(Upper(F(name)), name=gin_trgm_ops) on model repository
15+
--
16+
CREATE INDEX "repos_name_trgm_idx" ON "repos" USING gin ((UPPER("name")) gin_trgm_ops);
17+
COMMIT;
18+
"""
19+
20+
dependencies = [
21+
("core", "0076_increment_version"),
22+
]
23+
24+
operations = [
25+
RiskyAddIndex(
26+
model_name="repository",
27+
index=django.contrib.postgres.indexes.GinIndex(
28+
django.contrib.postgres.indexes.OpClass(
29+
django.db.models.functions.text.Upper("name"), name="gin_trgm_ops"
30+
),
31+
name="repos_name_trgm_idx",
32+
),
33+
),
34+
]

libs/shared/shared/django_apps/core/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class Meta:
153153
fields=["service_id", "author"],
154154
name="repos_service_id_author",
155155
),
156+
GinIndex(
157+
OpClass(Upper("name"), name="gin_trgm_ops"), name="repos_name_trgm_idx"
158+
),
156159
]
157160
constraints = [
158161
models.UniqueConstraint(fields=["author", "name"], name="repos_slug"),

0 commit comments

Comments
 (0)