File tree Expand file tree Collapse file tree
api/environments/identities Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Generated by Django 4.2.18 on 2025-04-22 10:15
2+
3+ from django .contrib .postgres .indexes import GinIndex
4+ from django .contrib .postgres .operations import TrigramExtension
5+ from django .db import migrations
6+ import django .contrib .postgres .indexes
7+ import django .db .models .functions .text
8+
9+ from core .migration_helpers import PostgresOnlyRunSQL
10+
11+
12+ _create_index_sql = "CREATE INDEX CONCURRENTLY IF NOT EXISTS identity_identifier_idx ON environments_identity USING GIN (UPPER(identifier) gin_trgm_ops);"
13+ _create_index_reverse_sql = (
14+ "DROP INDEX CONCURRENTLY IF EXISTS identity_identifier_idx;"
15+ )
16+
17+
18+ class Migration (migrations .Migration ):
19+ atomic = False
20+
21+ dependencies = [
22+ ("identities" , "0002_alter_identity_index_together" ),
23+ ]
24+
25+ operations = [
26+ migrations .SeparateDatabaseAndState (
27+ state_operations = [
28+ migrations .AddIndex (
29+ model_name = "identity" ,
30+ index = GinIndex (
31+ django .contrib .postgres .indexes .OpClass (
32+ django .db .models .functions .text .Upper ("identifier" ),
33+ name = "gin_trgm_ops" ,
34+ ),
35+ name = "identity_identifier_idx" ,
36+ ),
37+ ),
38+ ],
39+ database_operations = [
40+ TrigramExtension (),
41+ PostgresOnlyRunSQL (
42+ sql = _create_index_sql ,
43+ reverse_sql = _create_index_reverse_sql ,
44+ ),
45+ ],
46+ ),
47+ ]
Original file line number Diff line number Diff line change 11import typing
22from itertools import chain
33
4+ from django .contrib .postgres .indexes import GinIndex , OpClass
45from django .db import models
56from django .db .models import Prefetch , Q
7+ from django .db .models .functions import Upper
68from django .utils import timezone
79from flag_engine .segments .evaluator import evaluate_identity_in_segment
810
@@ -40,6 +42,12 @@ class Meta:
4042 # avoid any downtime. If people using MySQL / Oracle have issues with poor performance on the identities table,
4143 # we can provide them the SQL to add it manually in a small window of downtime.
4244 index_together = (("environment" , "created_date" ),)
45+ indexes = [
46+ GinIndex (
47+ OpClass (Upper ("identifier" ), name = "gin_trgm_ops" ),
48+ name = "identity_identifier_idx" ,
49+ ),
50+ ]
4351
4452 def natural_key (self ): # type: ignore[no-untyped-def]
4553 return self .identifier , self .environment .api_key
You can’t perform that action at this time.
0 commit comments