wip: add index of unaccented upper value of role.name
gitea/authentic/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2024-03-28 17:25:21 +01:00
parent 7e04fa9374
commit 12fc4ef9f0
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,29 @@
# Generated by Django 3.2.23 on 2024-03-28 16:50
import django.contrib.postgres.indexes
import django.db.models.expressions
import django.db.models.functions.text
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('a2_rbac', '0039_set_user_view_permissions_by_ou'),
]
operations = [
migrations.AddIndex(
model_name='role',
index=django.contrib.postgres.indexes.GinIndex(
django.contrib.postgres.indexes.OpClass(
django.db.models.functions.text.Upper(
django.db.models.expressions.Func(
django.db.models.expressions.F('name'), function='immutable_unaccent'
)
),
'public.gin_trgm_ops',
),
name='name_idx',
),
),
]

View File

@ -23,10 +23,12 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres import indexes as postgresql_indexes
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models.functions import Upper
from django.db.models.query import Prefetch, Q
from django.urls import reverse
from django.utils.text import slugify
@ -614,6 +616,14 @@ class Role(AbstractBase):
condition=models.Q(service__isnull=True, ou__isnull=True, admin_scope_ct__isnull=True),
),
]
indexes = [
postgresql_indexes.GinIndex(
postgresql_indexes.OpClass(
Upper(models.Func(models.F('name'), function='immutable_unaccent')), 'public.gin_trgm_ops'
),
name='name_idx',
),
]
def natural_key(self):
return [