Skip to content

Commit e625f11

Browse files
authored
fix: DEV-3839: Avoid creation of pg_trgm in postgres if it's already existing (#3395)
fix: DEV-3839: Avoid creation of pg_trgm in postgres if it's already existing (#3384) fix: DEV-3839: Avoid creation of pg_trgm in postgres if it's already exists
1 parent 76b7014 commit e625f11

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

label_studio/core/utils/common.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
from django_filters.rest_framework import DjangoFilterBackend
3636
from drf_yasg.inspectors import CoreAPICompatInspector, NotHandled
3737
from collections import defaultdict
38+
from django.contrib.postgres.operations import TrigramExtension
3839

40+
from core.utils.params import get_env
3941
from datetime import datetime
4042
from functools import wraps
4143
from pkg_resources import parse_version
@@ -658,3 +660,19 @@ def __exit__(self, type_, value, traceback):
658660
sender=sender,
659661
dispatch_uid=dispatch_uid
660662
)
663+
664+
665+
def trigram_migration_operations(next_step):
666+
ops = [
667+
TrigramExtension(),
668+
next_step,
669+
]
670+
SKIP_TRIGRAM_EXTENSION = get_env('SKIP_TRIGRAM_EXTENSION', None)
671+
if SKIP_TRIGRAM_EXTENSION == '1' or SKIP_TRIGRAM_EXTENSION == 'yes' or SKIP_TRIGRAM_EXTENSION == 'true':
672+
ops = [
673+
next_step
674+
]
675+
if SKIP_TRIGRAM_EXTENSION == 'full':
676+
ops = []
677+
678+
return ops

label_studio/tasks/migrations/0009_auto_20210913_0739.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33

44
from django.db import migrations
5-
from django.contrib.postgres.operations import TrigramExtension
5+
from core.utils.common import trigram_migration_operations
66

77
logger = logging.getLogger(__name__)
88

@@ -30,7 +30,4 @@ class Migration(migrations.Migration):
3030

3131
dependencies = [('tasks', '0008_auto_20210903_1332')]
3232

33-
operations = [
34-
TrigramExtension(),
35-
migrations.RunPython(forwards, backwards),
36-
]
33+
operations = trigram_migration_operations(migrations.RunPython(forwards, backwards))

label_studio/tasks/migrations/0017_new_index_anno_result.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33

44
from django.db import migrations
5-
from django.contrib.postgres.operations import TrigramExtension
5+
from core.utils.common import trigram_migration_operations
66

77
logger = logging.getLogger(__name__)
88

@@ -26,14 +26,11 @@ def backwards(apps, schema_editor):
2626
return
2727

2828
schema_editor.execute('drop index tasks_annotations_result_idx2;')
29-
29+
3030

3131
class Migration(migrations.Migration):
3232
atomic = False
3333

3434
dependencies = [('tasks', '0016_auto_20220414_1408')]
3535

36-
operations = [
37-
TrigramExtension(),
38-
migrations.RunPython(forwards, backwards),
39-
]
36+
operations = trigram_migration_operations(migrations.RunPython(forwards, backwards))

0 commit comments

Comments
 (0)