Files
zt-closet-backend/pkg/migration/000017_create_quota_grants.up.sql
T
2026-09-11 01:41:52 +08:00

21 lines
1.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 额度凭证表:承载有有效期的赠送额度(会员包/加量包/广告激励)。
CREATE TABLE `quota_grants` (
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`created_at` BIGINT NOT NULL DEFAULT 0 COMMENT '创建时间',
`updated_at` BIGINT NOT NULL DEFAULT 0 COMMENT '更新时间',
`deleted_at` BIGINT NOT NULL DEFAULT 0 COMMENT '删除时间(0 表示未删除)',
`created_by` BIGINT NOT NULL DEFAULT 0 COMMENT '创建人',
`updated_by` BIGINT NOT NULL DEFAULT 0 COMMENT '更新人',
`deleted_by` BIGINT NOT NULL DEFAULT 0 COMMENT '删除人',
`user_id` BIGINT NOT NULL DEFAULT 0 COMMENT '用户ID',
`quota_type` TINYINT NOT NULL DEFAULT 0 COMMENT '额度类型 1=cos上传 2=AI推荐 3=社区分享 4=衣柜分享',
`amount` BIGINT NOT NULL DEFAULT 0 COMMENT '赠送总量',
`used` BIGINT NOT NULL DEFAULT 0 COMMENT '已用量(Cos 永久额度扣减;AI/社区/衣柜 每日额度恒为 0)',
`source` TINYINT NOT NULL DEFAULT 0 COMMENT '来源 1=会员包 2=加量包 3=广告激励',
`expire_time` BIGINT NOT NULL DEFAULT 0 COMMENT '到期时间(秒,0 表示跟随 VIP 有效期)',
`ref_id` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '关联ID(订单号/广告记录ID)',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_grant_ref_type` (`ref_id`, `quota_type`),
KEY `idx_grant_user_type_expire` (`user_id`, `quota_type`, `expire_time`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '额度凭证表(有有效期赠送额度)';