feat(marketplace): add product_reviews migration
This commit is contained in:
parent
7534c1d50e
commit
4ac1bf7c25
1 changed files with 23 additions and 0 deletions
23
veza-backend-api/migrations/101_product_reviews.sql
Normal file
23
veza-backend-api/migrations/101_product_reviews.sql
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
-- v0.403 R1: Product reviews (buyer reviews on purchased products)
|
||||
-- UNIQUE(product_id, buyer_id) - one review per buyer per product
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'products')
|
||||
AND EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'orders') THEN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'product_reviews') THEN
|
||||
CREATE TABLE product_reviews (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE,
|
||||
buyer_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
order_id UUID NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
|
||||
rating INTEGER NOT NULL CHECK (rating >= 1 AND rating <= 5),
|
||||
comment TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
UNIQUE(product_id, buyer_id)
|
||||
);
|
||||
CREATE INDEX idx_product_reviews_product_id ON product_reviews(product_id);
|
||||
CREATE INDEX idx_product_reviews_buyer_id ON product_reviews(buyer_id);
|
||||
END IF;
|
||||
END IF;
|
||||
END $$;
|
||||
Loading…
Reference in a new issue