Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
fix: ajout de suffixes dynamiques pour les indexes
Browse files Browse the repository at this point in the history
Peut-être un poil overkill, mais assez simple
  • Loading branch information
ikarius committed Oct 11, 2024
1 parent 0c6fab4 commit 9ecdb71
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions dora/sirene/backup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

from django.db import connection, transaction

from .models import Establishment
Expand Down Expand Up @@ -48,18 +50,22 @@ def create_table(table_name: str):


def create_indexes(table_name: str):
def _suffix():
# pas de risque ici : cette table n'est pas utilisée par l'ORM Django
return f"{random.getrandbits(16*8):8x}"

create_indexes_ddl = f"""
CREATE INDEX {table_name}_full_text_trgm_idx ON public.{table_name} USING gin (full_search_text gin_trgm_ops);
CREATE INDEX {table_name}_code_commune_100bb2ad ON public.{table_name} USING btree (city_code);
CREATE INDEX {table_name}_code_commune_100bb2ad_like ON public.{table_name} USING btree (city_code varchar_pattern_ops);
CREATE INDEX {table_name}_is_siege_9c0272c3 ON public.{table_name} USING btree (is_siege);
CREATE INDEX {table_name}_name_d8569d90 ON public.{table_name} USING btree (name);
CREATE INDEX {table_name}_name_d8569d90_like ON public.{table_name} USING btree (name varchar_pattern_ops);
CREATE INDEX {table_name}_parent_name_1990928d ON public.{table_name} USING btree (parent_name);
CREATE INDEX {table_name}_parent_name_1990928d_like ON public.{table_name} USING btree (parent_name varchar_pattern_ops);
CREATE INDEX {table_name}_siren_b19f551a ON public.{table_name} USING btree (siren);
CREATE INDEX {table_name}_siren_b19f551a_like ON public.{table_name} USING btree (siren varchar_pattern_ops);
CREATE INDEX {table_name}_siret_3eb91925_like ON public.{table_name} USING btree (siret varchar_pattern_ops);
CREATE INDEX {table_name}_code_commune_{_suffix()} ON public.{table_name} USING btree (city_code);
CREATE INDEX {table_name}_code_commune_{_suffix()}_like ON public.{table_name} USING btree (city_code varchar_pattern_ops);
CREATE INDEX {table_name}_is_siege_{_suffix()} ON public.{table_name} USING btree (is_siege);
CREATE INDEX {table_name}_name_{_suffix()} ON public.{table_name} USING btree (name);
CREATE INDEX {table_name}_name_{_suffix()}_like ON public.{table_name} USING btree (name varchar_pattern_ops);
CREATE INDEX {table_name}_parent_name_{_suffix()} ON public.{table_name} USING btree (parent_name);
CREATE INDEX {table_name}_parent_name_{_suffix()}_like ON public.{table_name} USING btree (parent_name varchar_pattern_ops);
CREATE INDEX {table_name}_siren_{_suffix()} ON public.{table_name} USING btree (siren);
CREATE INDEX {table_name}_siren_{_suffix()}_like ON public.{table_name} USING btree (siren varchar_pattern_ops);
CREATE INDEX {table_name}_siret_{_suffix()}_like ON public.{table_name} USING btree (siret varchar_pattern_ops);
"""
with connection.cursor() as c:
c.execute(create_indexes_ddl)
Expand Down

0 comments on commit 9ecdb71

Please sign in to comment.