Skip to content

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

Add `unique_type` to discount line models - migration compatibility (#15951)

Piotr Zabieglik4cbcbdb4df85
diff --git a/saleor/discount/migrations/0073_add_unique_type.py b/saleor/discount/migrations/0073_add_unique_type.py
new file mode 100644
index 0000000000..5479de4433
--- /dev/null
+++ b/saleor/discount/migrations/0073_add_unique_type.py
@@ -0,0 +1,68 @@
+# Generated by Django 3.2.24 on 2024-04-08 11:16
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("discount", "0072_promotionrule_variants_dirty"),
+ ]
+
+ operations = [
+ migrations.SeparateDatabaseAndState(
+ database_operations=[
+ migrations.RunSQL(
+ """
+ ALTER TABLE discount_checkoutlinediscount
+ ADD COLUMN IF NOT EXISTS unique_type varchar(64) NULL;
+ """,
+ reverse_sql="""
+ ALTER TABLE discount_checkoutlinediscount
+ DROP COLUMN IF EXISTS unique_type
+ """,
+ ),
+ migrations.RunSQL(
+ """
+ ALTER TABLE discount_orderlinediscount
+ ADD COLUMN IF NOT EXISTS unique_type varchar(64) NULL;
+ """,
+ reverse_sql="""
+ ALTER TABLE discount_orderlinediscount
+ DROP COLUMN IF EXISTS unique_type
+ """,
+ ),
+ ],
+ state_operations=[
+ migrations.AddField(
+ model_name="checkoutlinediscount",
+ name="unique_type",
+ field=models.CharField(
+ blank=True,
+ choices=[
+ ("sale", "Sale"),
+ ("voucher", "Voucher"),
+ ("manual", "Manual"),
+ ("promotion", "Promotion"),
+ ],
+ max_length=64,
+ null=True,
+ ),
+ ),
+ migrations.AddField(
+ model_name="orderlinediscount",
+ name="unique_type",
+ field=models.CharField(
+ blank=True,
+ choices=[
+ ("sale", "Sale"),
+ ("voucher", "Voucher"),
+ ("manual", "Manual"),
+ ("promotion", "Promotion"),
+ ],
+ max_length=64,
+ null=True,
+ ),
+ ),
+ ],
+ )
+ ]
diff --git a/saleor/discount/migrations/0074_add_index_for_unique_type.py b/saleor/discount/migrations/0074_add_index_for_unique_type.py
new file mode 100644
index 0000000000..651dc9462e
--- /dev/null
+++ b/saleor/discount/migrations/0074_add_index_for_unique_type.py
@@ -0,0 +1,33 @@
+# Generated by Django 3.2.24 on 2024-04-08 11:18
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ atomic = False
+ dependencies = [
+ ("discount", "0073_add_unique_type"),
+ ]
+
+ operations = [
+ migrations.RunSQL(
+ sql="""
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS unique_checkoutline_discount_type
+ ON discount_checkoutlinediscount USING btree (line_id, unique_type);
+ """,
+ reverse_sql="""
+ DROP INDEX CONCURRENTLY IF EXISTS
+ unique_checkoutline_discount_type;
+ """,
+ ),
+ migrations.RunSQL(
+ sql="""
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS unique_orderline_discount_type
+ ON discount_orderlinediscount USING btree (line_id, unique_type);
+ """,
+ reverse_sql="""
+ DROP INDEX CONCURRENTLY IF EXISTS
+ unique_orderline_discount_type;
+ """,
+ ),
+ ]
diff --git a/saleor/discount/migrations/0075_add_unique_type_constraint.py b/saleor/discount/migrations/0075_add_unique_type_constraint.py
new file mode 100644
index 0000000000..537a067ff8
--- /dev/null
+++ b/saleor/discount/migrations/0075_add_unique_type_constraint.py
@@ -0,0 +1,74 @@
+# Generated by Django 3.2.24 on 2024-04-08 11:20
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("discount", "0074_add_index_for_unique_type"),
+ ]
+
+ operations = [
+ migrations.SeparateDatabaseAndState(
+ database_operations=[
+ migrations.RunSQL(
+ sql="""
+ DO
+ $do$
+ BEGIN
+ IF NOT EXISTS (
+ SELECT 1 FROM pg_catalog.pg_constraint
+ WHERE conname LIKE 'unique_checkoutline_discount_type'
+ ) THEN
+ ALTER TABLE discount_checkoutlinediscount
+ ADD CONSTRAINT unique_checkoutline_discount_type
+ UNIQUE USING INDEX unique_checkoutline_discount_type;
+ END IF;
+ END
+ $do$
+ """,
+ reverse_sql="""
+ ALTER TABLE discount_checkoutlinediscount
+ DROP CONSTRAINT IF EXISTS unique_checkoutline_discount_type;
+ """,
+ ),
+ migrations.RunSQL(
+ sql="""
+ DO
+ $do$
+ BEGIN
+ IF NOT EXISTS (
+ SELECT 1 FROM pg_catalog.pg_constraint
+ WHERE conname LIKE 'unique_orderline_discount_type'
+ ) THEN
+ ALTER TABLE discount_orderlinediscount
+ ADD CONSTRAINT unique_orderline_discount_type
+ UNIQUE USING INDEX unique_orderline_discount_type;
+ END IF;
+ END
+ $do$
+ """,
+ reverse_sql="""
+ ALTER TABLE discount_orderlinediscount
+ DROP CONSTRAINT IF EXISTS unique_orderline_discount_type;
+ """,
+ ),
+ ],
+ state_operations=[
+ migrations.AddConstraint(
+ model_name="checkoutlinediscount",
+ constraint=models.UniqueConstraint(
+ fields=("line_id", "unique_type"),
+ name="unique_checkoutline_discount_type",
+ ),
+ ),
+ migrations.AddConstraint(
+ model_name="orderlinediscount",
+ constraint=models.UniqueConstraint(
+ fields=("line_id", "unique_type"),
+ name="unique_orderline_discount_type",
+ ),
+ ),
+ ],
+ )
+ ]
diff --git a/saleor/discount/migrations/0078_add_unique_type.py b/saleor/discount/migrations/0078_add_unique_type.py
index 85dd280310..de558447b3 100644
--- a/saleor/discount/migrations/0078_add_unique_type.py
+++ b/saleor/discount/migrations/0078_add_unique_type.py
@@ -1,6 +1,6 @@
# Generated by Django 3.2.24 on 2024-04-08 11:16
-from django.db import migrations, models
+from django.db import migrations
class Migration(migrations.Migration):
@@ -8,37 +8,6 @@ class Migration(migrations.Migration):
("discount", "0077_merge_20240307_1217"),
]
- operations = [
- migrations.AddField(
- model_name="checkoutlinediscount",
- name="unique_type",
- field=models.CharField(
- blank=True,
- choices=[
- ("sale", "Sale"),
- ("voucher", "Voucher"),
- ("manual", "Manual"),
- ("promotion", "Promotion"),
- ("order_promotion", "Order promotion"),
- ],
- max_length=64,
- null=True,
- ),
- ),
- migrations.AddField(
- model_name="orderlinediscount",
- name="unique_type",
- field=models.CharField(
- blank=True,
- choices=[
- ("sale", "Sale"),
- ("voucher", "Voucher"),
- ("manual", "Manual"),
- ("promotion", "Promotion"),
- ("order_promotion", "Order promotion"),
- ],
- max_length=64,
- null=True,
- ),
- ),
- ]
+ # left to keep migration compatibility
+ # the logic moved to 0073_add_unique_type
+ operations = []
diff --git a/saleor/discount/migrations/0079_add_index_for_unique_type.py b/saleor/discount/migrations/0079_add_index_for_unique_type.py
index b97205ae32..5b35d4df41 100644
--- a/saleor/discount/migrations/0079_add_index_for_unique_type.py
+++ b/saleor/discount/migrations/0079_add_index_for_unique_type.py
@@ -4,30 +4,10 @@ from django.db import migrations
class Migration(migrations.Migration):
- atomic = False
dependencies = [
("discount", "0078_add_unique_type"),
]
- operations = [
- migrations.RunSQL(
- sql="""
- CREATE UNIQUE INDEX CONCURRENTLY checkoutlinediscount_line_id_unique_type_idx
- ON discount_checkoutlinediscount USING btree (line_id, unique_type);
- """,
- reverse_sql="""
- DROP INDEX CONCURRENTLY IF EXISTS
- checkoutlinediscount_line_id_unique_type_idx;
- """,
- ),
- migrations.RunSQL(
- sql="""
- CREATE UNIQUE INDEX CONCURRENTLY orderlinediscount_line_id_unique_type_idx
- ON discount_orderlinediscount USING btree (line_id, unique_type);
- """,
- reverse_sql="""
- DROP INDEX CONCURRENTLY IF EXISTS
- orderlinediscount_line_id_unique_type_idx;
- """,
- ),
- ]
+ # left to keep migration compatibility
+ # the logic moved to 0074_add_index_for_unique_type
+ operations = []
diff --git a/saleor/discount/migrations/0080_add_unique_type_constraint.py b/saleor/discount/migrations/0080_add_unique_type_constraint.py
index ce3c8e8e00..a4c72144a7 100644
--- a/saleor/discount/migrations/0080_add_unique_type_constraint.py
+++ b/saleor/discount/migrations/0080_add_unique_type_constraint.py
@@ -1,6 +1,6 @@
# Generated by Django 3.2.24 on 2024-04-08 11:20
-from django.db import migrations, models
+from django.db import migrations
class Migration(migrations.Migration):
@@ -8,47 +8,6 @@ class Migration(migrations.Migration):
("discount", "0079_add_index_for_unique_type"),
]
- operations = [
- migrations.SeparateDatabaseAndState(
- database_operations=[
- migrations.RunSQL(
- sql="""
- ALTER TABLE discount_checkoutlinediscount
- ADD CONSTRAINT unique_checkoutline_discount_type
- UNIQUE USING INDEX checkoutlinediscount_line_id_unique_type_idx;
- """,
- reverse_sql="""
- ALTER TABLE discount_checkoutlinediscount DROP CONSTRAINT IF EXISTS
- unique_checkoutline_discount_type;
- """,
- ),
- migrations.RunSQL(
- sql="""
- ALTER TABLE discount_orderlinediscount
- ADD CONSTRAINT unique_orderline_discount_type
- UNIQUE USING INDEX orderlinediscount_line_id_unique_type_idx;
- """,
- reverse_sql="""
- ALTER TABLE discount_orderlinediscount DROP CONSTRAINT IF EXISTS
- unique_orderline_discount_type;
- """,
- ),
- ],
- state_operations=[
- migrations.AddConstraint(
- model_name="checkoutlinediscount",
- constraint=models.UniqueConstraint(
- fields=("line_id", "unique_type"),
- name="unique_checkoutline_discount_type",
- ),
- ),
- migrations.AddConstraint(
- model_name="orderlinediscount",
- constraint=models.UniqueConstraint(
- fields=("line_id", "unique_type"),
- name="unique_orderline_discount_type",
- ),
- ),
- ],
- )
- ]
+ # left to keep migration compatibility
+ # the logic moved to 0075_add_unique_type_constraint
+ operations = []
diff --git a/saleor/discount/migrations/0082_merge_20240509_1550.py b/saleor/discount/migrations/0082_merge_20240509_1550.py
new file mode 100644
index 0000000000..dbc15f7848
--- /dev/null
+++ b/saleor/discount/migrations/0082_merge_20240509_1550.py
@@ -0,0 +1,12 @@
+# Generated by Django 3.2.24 on 2024-05-09 15:50
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("discount", "0075_add_unique_type_constraint"),
+ ("discount", "0081_merge_20240422_1207"),
+ ]
+
+ operations = []
diff --git a/saleor/discount/migrations/0083_auto_20240510_0838.py b/saleor/discount/migrations/0083_auto_20240510_0838.py
new file mode 100644
index 0000000000..25632c6f8f
--- /dev/null
+++ b/saleor/discount/migrations/0083_auto_20240510_0838.py
@@ -0,0 +1,44 @@
+# Generated by Django 3.2.24 on 2024-05-10 08:38
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("discount", "0082_merge_20240509_1550"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="checkoutlinediscount",
+ name="unique_type",
+ field=models.CharField(
+ blank=True,
+ choices=[
+ ("sale", "Sale"),
+ ("voucher", "Voucher"),
+ ("manual", "Manual"),
+ ("promotion", "Promotion"),
+ ("order_promotion", "Order promotion"),
+ ],
+ max_length=64,
+ null=True,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="orderlinediscount",
+ name="unique_type",
+ field=models.CharField(
+ blank=True,
+ choices=[
+ ("sale", "Sale"),
+ ("voucher", "Voucher"),
+ ("manual", "Manual"),
+ ("promotion", "Promotion"),
+ ("order_promotion", "Order promotion"),
+ ],
+ max_length=64,
+ null=True,
+ ),
+ ),
+ ]