From 3a90bb553c999e63e02d5cd859f150ebde69d02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arwid=20Thornstr=C3=B6m?= Date: Tue, 27 May 2025 13:30:50 +0200 Subject: [PATCH] 7224 build system in photowall repo and admin to handle generating product descriptions in different languages with gemeni ai and specialized prompt (#482) * add product description tracking table * added description tracking table * create product_description_updated table * updated with indexes * fixed table with indexes * fix * correct migration number --- migrations/000.555.sql | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 migrations/000.555.sql diff --git a/migrations/000.555.sql b/migrations/000.555.sql new file mode 100644 index 0000000..c6e9a1b --- /dev/null +++ b/migrations/000.555.sql @@ -0,0 +1,46 @@ +DROP TABLE IF EXISTS product_descriptions_updated CASCADE; + +CREATE TABLE product_descriptions_updated ( + id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + productid INT NOT NULL, + locale_id INT NOT NULL, + product_type VARCHAR(50) NOT NULL, + updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- Foreign key constraint for productid + -- This constraint creates a foreign key relationship between the 'productid' column in the current table + -- and the 'productid' column in the 'product-products' table. The ON DELETE CASCADE clause means that if a product is + -- deleted from the 'product-products' table, all corresponding rows in this table will also be automatically deleted. + CONSTRAINT fk_product_descriptions_updated_product + FOREIGN KEY (productid) REFERENCES "product-products"(productid) + ON DELETE CASCADE, + + -- Foreign key constraint for locale_id + -- This constraint creates a foreign key relationship between the 'locale_id' column in the current table + -- and the 'id' column in the 'locales' table. The ON DELETE CASCADE clause means that if a locale is + -- deleted from the 'locales' table, all corresponding rows in this table will also be automatically deleted. + CONSTRAINT fk_product_descriptions_updated_locale + FOREIGN KEY (locale_id) REFERENCES locales(id) + ON DELETE CASCADE, + + -- Check constraint for product_type + -- This constraint ensures that the product_type column only contains allowed values + -- It restricts the product_type to be one of: 'wallpaper', 'canvas', or 'poster' + -- Any attempt to insert or update a record with a different product_type will fail + CONSTRAINT chk_product_descriptions_updated_product_type + CHECK (product_type IN ('wallpaper', 'canvas', 'poster')) +); + +-- Additional indexes for query performance +CREATE INDEX idx_product_descriptions_updated_productid + ON product_descriptions_updated (productid); + +CREATE INDEX idx_product_descriptions_updated_locale_id + ON product_descriptions_updated (locale_id); + +CREATE INDEX idx_product_descriptions_updated_updated + ON product_descriptions_updated (updated DESC); + +-- Unique index to ensure one record per product, locale, and product type combination +CREATE UNIQUE INDEX unique_product_locale_product_type + ON product_descriptions_updated (productid, locale_id, product_type);