<aside>
</aside>
promotions| Column | Type | Null | Default | Notes |
|---|---|---|---|---|
id |
UUID |
NO | PK | |
campaign_id |
UUID |
YES | NULL |
FK → promotion_campaigns(id) ON DELETE SET NULL |
code |
VARCHAR |
NO | UNIQUE, mã giảm giá | |
description |
TEXT |
YES | ||
type |
promotion_type |
NO | Enum: percent |
|
discount_percent |
INT |
YES | Phần trăm giảm (chỉ khi type='percent') |
|
discount_cap |
INT |
YES | NULL |
Giá trị tiền tối đa được giảm (chỉ khi type='percent'; NULL = không giới hạn) |
discount_amount |
INT |
YES | Số tiền giảm cố định (chỉ khi type='fixed') |
|
usage_limit |
INT |
NO | 0 |
0 = unlimited |
usage_per_user |
INT |
NO | 1 |
Lượt dùng tối đa mỗi user |
start_at |
TIMESTAMP |
NO | Ngày bắt đầu áp dụng | |
end_at |
TIMESTAMP |
NO | Ngày kết thúc áp dụng | |
status |
promotion_status |
NO | 'active' |
Enum: active |
created_at |
TIMESTAMP |
NO | now() |
|
updated_at |
TIMESTAMP |
NO | now() |
|
deleted_at |
TIMESTAMP |
YES | NULL |
Ràng buộc CHECK:
ALTER TABLE promotions
ADD CONSTRAINT promotions_type_check CHECK (
(type = 'percent'
AND discount_percent IS NOT NULL
AND discount_amount IS NULL)
OR
(type = 'fixed'
AND discount_amount IS NOT NULL
AND discount_percent IS NULL
AND discount_cap IS NULL)
);
Index gợi ý (tăng tốc tìm khuyến mãi đang active):
CREATE INDEX idx_active_promotions
ON promotions(start_at, end_at)
WHERE status = 'active';