From 289763eab0723822f2f51aeade5a5d7ff63f0a5f Mon Sep 17 00:00:00 2001 From: bearthatcares <149488155+bearthatcares@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:22:39 -0500 Subject: [PATCH] Add indexes to StandingFleetVoiceRecord for SQL querying (#964) --- ...leetvoicerecord_created_on_idx_and_more.py | 21 +++++++++++++++++++ backend/standingfleet/models.py | 8 +++++++ 2 files changed, 29 insertions(+) create mode 100644 backend/standingfleet/migrations/0002_standingfleetvoicerecord_created_on_idx_and_more.py diff --git a/backend/standingfleet/migrations/0002_standingfleetvoicerecord_created_on_idx_and_more.py b/backend/standingfleet/migrations/0002_standingfleetvoicerecord_created_on_idx_and_more.py new file mode 100644 index 00000000..8f0731e8 --- /dev/null +++ b/backend/standingfleet/migrations/0002_standingfleetvoicerecord_created_on_idx_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 5.1.2 on 2024-12-13 15:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("standingfleet", "0001_initial"), + ] + + operations = [ + migrations.AddIndex( + model_name="standingfleetvoicerecord", + index=models.Index(fields=["created_on"], name="created_on_idx"), + ), + migrations.AddIndex( + model_name="standingfleetvoicerecord", + index=models.Index(fields=["username"], name="username_idx"), + ), + ] diff --git a/backend/standingfleet/models.py b/backend/standingfleet/models.py index 27c1c80a..6a705025 100644 --- a/backend/standingfleet/models.py +++ b/backend/standingfleet/models.py @@ -6,3 +6,11 @@ class StandingFleetVoiceRecord(models.Model): created_on = models.DateTimeField(auto_now_add=True) username = models.CharField(max_length=255) minutes = models.IntegerField() + + class Meta: + indexes = [ + # Index on 'created_on' for queries filtering by creation date + models.Index(fields=["created_on"], name="created_on_idx"), + # Index on 'username' for queries filtering by username + models.Index(fields=["username"], name="username_idx"), + ]