From 3911583248b1faf379ead59309ef5828ba87e1f3 Mon Sep 17 00:00:00 2001 From: IKarbowiak Date: Tue, 30 May 2023 18:06:02 +0200 Subject: [PATCH] Add index on product model --- .../migrations/0009_product_product_index.py | 17 +++++++++++++++++ zerodowntime/zerodowntime/product/models.py | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 zerodowntime/zerodowntime/product/migrations/0009_product_product_index.py diff --git a/zerodowntime/zerodowntime/product/migrations/0009_product_product_index.py b/zerodowntime/zerodowntime/product/migrations/0009_product_product_index.py new file mode 100644 index 0000000..26b1cb0 --- /dev/null +++ b/zerodowntime/zerodowntime/product/migrations/0009_product_product_index.py @@ -0,0 +1,17 @@ +from django.contrib.postgres.operations import AddIndexConcurrently +from django.db import migrations, models + + +class Migration(migrations.Migration): + atomic = False + + dependencies = [ + ("product", "0008_merge_20230527_0946"), + ] + + operations = [ + AddIndexConcurrently( + model_name="product", + index=models.Index(fields=["name", "slug"], name="product_index"), + ) + ] diff --git a/zerodowntime/zerodowntime/product/models.py b/zerodowntime/zerodowntime/product/models.py index 3171517..48d6b63 100644 --- a/zerodowntime/zerodowntime/product/models.py +++ b/zerodowntime/zerodowntime/product/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Index class Product(models.Model): @@ -10,6 +11,12 @@ class Product(models.Model): class Meta: ordering = ("pk",) + indexes = [ + Index( + name="product_index", + fields=["name", "slug"], + ), + ] def __str__(self) -> str: return self.name