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
This commit is contained in:
@@ -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)
|
||||
);
|
||||
Reference in New Issue
Block a user