From 944605044d17c279f36a4939bb9d23e4b4470246 Mon Sep 17 00:00:00 2001 From: Viktor89PW Date: Mon, 2 Feb 2026 10:50:35 +0100 Subject: [PATCH] 8726 swapped product db table (#530) * Add sql for swapped table * Fix swapped_designer_products table schema: rename column and enforce uniqueness constraints * Remove drop if exists * Change filename for merge with master * Change table name * Corrected file name * Corrected comment * Change migration name for merge --- migrations/000.605.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 migrations/000.605.sql diff --git a/migrations/000.605.sql b/migrations/000.605.sql new file mode 100644 index 0000000..329b6e2 --- /dev/null +++ b/migrations/000.605.sql @@ -0,0 +1,13 @@ +-- Migration: 000.604.sql +-- Description: Create table for tracking swapped products with cascade delete behavior +CREATE TABLE swapped_products ( + id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + original_product_id INTEGER NOT NULL REFERENCES "product-products"(productid), + new_product_id INTEGER NOT NULL REFERENCES "product-products"(productid), + swapped_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- Ensure unique combination of original and swapped product (prevent duplicates) + UNIQUE(original_product_id), + UNIQUE(new_product_id), + CHECK (original_product_id IS DISTINCT FROM new_product_id) +);