feat(reviews): order-line reviews with merchant reply and platform moderation (add-product-reviews)

This commit is contained in:
Chengdong Zhang
2026-09-24 16:38:05 +08:00
parent 473d19d089
commit c532f87b03
34 changed files with 2055 additions and 36 deletions
@@ -0,0 +1,22 @@
CREATE TABLE product_reviews (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
order_item_id UUID NOT NULL REFERENCES order_items (id),
order_id UUID NOT NULL REFERENCES orders (id),
product_id UUID NOT NULL REFERENCES products (id),
shop_id UUID NOT NULL REFERENCES shops (id),
user_id UUID NOT NULL REFERENCES users (id),
rating INT NOT NULL CHECK (rating BETWEEN 1 AND 5),
content JSONB NOT NULL,
images JSONB NOT NULL DEFAULT '[]',
reply JSONB,
reply_at TIMESTAMPTZ,
status TEXT NOT NULL DEFAULT 'visible' CHECK (status IN ('visible', 'hidden')),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- At most one review per order line, forever.
CREATE UNIQUE INDEX product_reviews_one_per_line ON product_reviews (order_item_id);
CREATE INDEX idx_product_reviews_product ON product_reviews (product_id) WHERE status = 'visible';
CREATE INDEX idx_product_reviews_shop ON product_reviews (shop_id);
CREATE INDEX idx_product_reviews_user ON product_reviews (user_id);