Skip to content

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

Migrate DB order events

Tomasz Szymanskiba10fa8d8f6f
diff --git a/saleor/order/migrations/0103_auto_20210401_1105.py b/saleor/order/migrations/0103_auto_20210401_1105.py
index e90ba20f36..89786a0b81 100644
--- a/saleor/order/migrations/0103_auto_20210401_1105.py
+++ b/saleor/order/migrations/0103_auto_20210401_1105.py
@@ -3,6 +3,22 @@
from django.db import migrations, models
+def update_existing_order_events_in_db(apps, schema_editor):
+ OrderEvent = apps.get_model("order", "OrderEvent")
+ OrderEvent.objects.filter(type="draft_added_products").update(type="added_products")
+ OrderEvent.objects.filter(type="draft_removed_products").update(
+ type="removed_products"
+ )
+
+
+def revert_existing_order_events_in_db(apps, schema_editor):
+ OrderEvent = apps.get_model("order", "OrderEvent")
+ OrderEvent.objects.filter(type="added_products").update(type="draft_added_products")
+ OrderEvent.objects.filter(type="removed_products").update(
+ type="draft_removed_products"
+ )
+
+
class Migration(migrations.Migration):
dependencies = [
@@ -61,4 +77,8 @@ class Migration(migrations.Migration):
max_length=255,
),
),
+ migrations.RunPython(
+ update_existing_order_events_in_db,
+ reverse_code=revert_existing_order_events_in_db,
+ ),
]