Files
Viktor89PWandGitHub 944605044d 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
2026-02-02 10:50:35 +01:00

14 lines
651 B
SQL

-- 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)
);