Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Move to adding index concurrently and move data migration to a separate step

Ania Warzechab69081f9337a
diff --git a/saleor/attribute/migrations/0030_assignedproductattributevalue_product.py b/saleor/attribute/migrations/0030_assignedproductattributevalue_product.py
index d78b478490..6ab6f3af66 100644
--- a/saleor/attribute/migrations/0030_assignedproductattributevalue_product.py
+++ b/saleor/attribute/migrations/0030_assignedproductattributevalue_product.py
@@ -2,18 +2,6 @@
from django.db import migrations, models
import django.db.models.deletion
-from django.db.models.signals import post_migrate
-from django.apps import apps as registry
-
-from .tasks.saleor3_16 import assign_products_to_attribute_values_task
-
-
-def enqueue_data_migration(apps, _schema_editor):
- def on_migrations_complete(sender=None, **kwargs):
- assign_products_to_attribute_values_task.delay()
-
- sender = registry.get_app_config("attribute")
- post_migrate.connect(on_migrations_complete, weak=False, sender=sender)
class Migration(migrations.Migration):
@@ -32,7 +20,7 @@ class Migration(migrations.Migration):
on_delete=django.db.models.deletion.CASCADE,
related_name="attributevalues",
to="product.product",
+ db_index=False,
),
),
- migrations.RunPython(enqueue_data_migration, migrations.RunPython.noop),
]
diff --git a/saleor/attribute/migrations/0035_assignedproductattributevalue_product_add_index.py b/saleor/attribute/migrations/0035_assignedproductattributevalue_product_add_index.py
new file mode 100644
index 0000000000..bd7cb4f64e
--- /dev/null
+++ b/saleor/attribute/migrations/0035_assignedproductattributevalue_product_add_index.py
@@ -0,0 +1,20 @@
+# Generated by Django 3.2.20 on 2023-08-24 11:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("attribute", "0034_assignedpageattributevalue_page_data_migration"),
+ ]
+
+ operations = [
+ migrations.RunSQL(
+ '''
+ CREATE INDEX CONCURRENTLY "assignedproductattrvalue_product_idx"
+ ON assignedproductattributevalue("product") using btree;
+ '''
+ )
+ ]
diff --git a/saleor/attribute/migrations/0036_assignedproductattributevalue_product_data_migration.py b/saleor/attribute/migrations/0036_assignedproductattributevalue_product_data_migration.py
new file mode 100644
index 0000000000..012641a0fa
--- /dev/null
+++ b/saleor/attribute/migrations/0036_assignedproductattributevalue_product_data_migration.py
@@ -0,0 +1,25 @@
+# Generated by Django 3.2.20 on 2023-08-24 11:25
+
+from django.db import migrations
+from django.db.models.signals import post_migrate
+from django.apps import apps as registry
+
+from .tasks.saleor3_16 import assign_products_to_attribute_values_task
+
+
+def data_migration(apps, _schema_editor):
+ def on_migrations_complete(sender=None, **kwargs):
+ assign_products_to_attribute_values_task.delay()
+
+ sender = registry.get_app_config("attribute")
+ post_migrate.connect(on_migrations_complete, weak=False, sender=sender)
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("attribute", "0035_assignedproductattributevalue_product_add_index"),
+ ]
+
+ operations = [
+ migrations.RunPython(data_migration, migrations.RunPython.noop),
+ ]