【发布时间】:2011-07-18 02:29:50
【问题描述】:
我有一个应用程序,用户可以在其中锁定某种商品,一旦他锁定它,他必须在 2 小时内取走它。如果他在 2 小时内没有捡起它,则该物品被解锁并且用户失去 1 次锁定机会。用户最初有 3 次锁定机会,如果他在 2 个月内失去所有 3 次锁定机会,则会被禁止 2 个月。现在我已经为此准备了一个模式,但我觉得它不是最佳的。架构看起来像这样
user table
--locking_chances_left //initially 3
--first_chance_miss_date //date on which the user loses its first locking chance
--second_chance_miss_date //date on which the user loses its second locking chance
--banned // boolean field to indicate whether the user is banned
locked_items table
--item_no
--user_id
--locking_time
banned_users table
--user_id
--ban_date //date on which the user is banned i.e lost the last chance
现在我有一个计划每分钟运行一次的事件,以查看 locked_items 表中的任何项目是否已锁定超过 2 小时,如果找到任何项目,则将其从该表中删除,从而解锁该项目并然后从users 表中将locking_chances_left 减1。现在我必须跟踪用户是否在 2 个月内失去了禁止他的所有机会。所以我保留了first_chance_miss_date 以保留他的机会从 3 减少到 2 的日期和 second_chance_miss_date 保留他的机会从 2 减少到 1 的日期。我在 users 表上有一个 after update trigger 来检查何时locking_chances_left 的值已更改,它会相应地更新 first_chance_miss_date 和 second_chance_miss_date。有没有更好的方法而不使用miss dates 的这两个字段而只使用一个字段。
谢谢你承受这个
【问题讨论】:
标签: mysql events triggers schema