base_adresse: add indexes on on geographic models names (#66694) #440
|
@ -0,0 +1,67 @@
|
|||
# Generated by Django 3.2.18 on 2023-11-29 18:06
|
||||
|
||||
import django.contrib.postgres.indexes
|
||||
import django.db.models.functions.text
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('base_adresse', '0030_auto_20220627_1511'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunSQL(
|
||||
[
|
||||
'CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public',
|
||||
],
|
||||
reverse_sql=['DROP EXTENSION IF EXISTS pg_trgm'],
|
||||
),
|
||||
bdauvergne marked this conversation as resolved
Outdated
|
||||
migrations.AddIndex(
|
||||
model_name='citymodel',
|
||||
index=models.Index(fields=['code'], name='base_adress_code_e169d0_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='citymodel',
|
||||
index=models.Index(fields=['zipcode'], name='base_adress_zipcode_79aa6f_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='citymodel',
|
||||
index=models.Index(
|
||||
django.db.models.functions.text.Upper('unaccent_name'), name='base_adresse_city_name_idx'
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='departmentmodel',
|
||||
index=models.Index(
|
||||
django.db.models.functions.text.Upper('unaccent_name'), name='base_adresse_dept_name_idx'
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='regionmodel',
|
||||
index=models.Index(
|
||||
django.db.models.functions.text.Upper('unaccent_name'), name='base_adresse_region_name_idx'
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='streetmodel',
|
||||
index=models.Index(fields=['ban_id'], name='base_adress_ban_id_2c35ab_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='streetmodel',
|
||||
index=models.Index(fields=['zipcode'], name='base_adress_zipcode_bf7091_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='streetmodel',
|
||||
index=models.Index(fields=['citycode'], name='base_adress_citycod_428b79_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='streetmodel',
|
||||
index=django.contrib.postgres.indexes.GinIndex(
|
||||
django.contrib.postgres.indexes.OpClass(
|
||||
django.db.models.functions.text.Upper('unaccent_name'), 'public.gin_trgm_ops'
|
||||
),
|
||||
name='base_adresse_street_name_idx',
|
||||
),
|
||||
),
|
||||
]
|
|
@ -5,9 +5,11 @@ import json
|
|||
from io import StringIO
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from django.contrib.postgres import indexes as postgresql_indexes
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db import connection, models
|
||||
from django.db.models import JSONField, Q
|
||||
from django.db.models.functions import Upper
|
||||
from django.utils import timezone
|
||||
from django.utils.http import urlencode
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -735,6 +737,15 @@ class StreetModel(UnaccentNameMixin, models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ['unaccent_name', 'name']
|
||||
indexes = [
|
||||
models.Index(fields=['ban_id']),
|
||||
models.Index(fields=['zipcode']),
|
||||
models.Index(fields=['citycode']),
|
||||
postgresql_indexes.GinIndex(
|
||||
postgresql_indexes.OpClass(Upper('unaccent_name'), 'public.gin_trgm_ops'),
|
||||
name='%(app_label)s_street_name_idx',
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
@ -759,6 +770,9 @@ class RegionModel(UnaccentNameMixin, models.Model):
|
|||
class Meta:
|
||||
ordering = ['code']
|
||||
unique_together = ('resource', 'code')
|
||||
indexes = [
|
||||
models.Index(Upper('unaccent_name'), name='%(app_label)s_region_name_idx'),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return '%s %s' % (self.code, self.name)
|
||||
|
@ -786,6 +800,9 @@ class DepartmentModel(UnaccentNameMixin, models.Model):
|
|||
class Meta:
|
||||
ordering = ['code']
|
||||
unique_together = ('resource', 'code')
|
||||
indexes = [
|
||||
models.Index(Upper('unaccent_name'), name='%(app_label)s_dept_name_idx'),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return '%s %s' % (self.code, self.name)
|
||||
|
@ -823,6 +840,11 @@ class CityModel(UnaccentNameMixin, models.Model):
|
|||
class Meta:
|
||||
ordering = ['-population', 'zipcode', 'unaccent_name', 'name']
|
||||
unique_together = ('resource', 'code', 'zipcode')
|
||||
indexes = [
|
||||
models.Index(fields=['code']),
|
||||
models.Index(fields=['zipcode']),
|
||||
models.Index(Upper('unaccent_name'), name='%(app_label)s_city_name_idx'),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return '%s %s' % (self.zipcode, self.name)
|
||||
|
|
Loading…
Reference in New Issue
D'un côté pg_trgme et de l'autre pg_trgm ?
Fatigue.. merci.