Initialize clean CSR inventory repository

This commit is contained in:
DenisToxic
2026-09-29 08:43:05 +02:00
commit 059f386c60
107 changed files with 9639 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
from django.db import migrations
def add_postgres_indexes(apps, schema_editor):
if schema_editor.connection.vendor != "postgresql":
return
statements = [
"CREATE EXTENSION IF NOT EXISTS pg_trgm",
"CREATE INDEX IF NOT EXISTS inventory_device_cpu_trgm ON inventory_device USING gin (cpu gin_trgm_ops)",
"CREATE INDEX IF NOT EXISTS inventory_device_model_trgm ON inventory_device USING gin (model gin_trgm_ops)",
"CREATE INDEX IF NOT EXISTS inventory_device_ticket_trgm ON inventory_device USING gin (ticket gin_trgm_ops)",
"CREATE INDEX IF NOT EXISTS inventory_device_donor_trgm ON inventory_device USING gin (donor gin_trgm_ops)",
"CREATE INDEX IF NOT EXISTS inventory_device_custom_values_gin ON inventory_device USING gin (custom_values jsonb_path_ops)",
]
with schema_editor.connection.cursor() as cursor:
for statement in statements:
cursor.execute(statement)
def remove_postgres_indexes(apps, schema_editor):
if schema_editor.connection.vendor != "postgresql":
return
with schema_editor.connection.cursor() as cursor:
for name in ["inventory_device_cpu_trgm", "inventory_device_model_trgm", "inventory_device_ticket_trgm", "inventory_device_donor_trgm", "inventory_device_custom_values_gin"]:
cursor.execute(f"DROP INDEX IF EXISTS {name}")
class Migration(migrations.Migration):
dependencies = [("inventory", "0001_initial")]
operations = [migrations.RunPython(add_postgres_indexes, remove_postgres_indexes)]