在数据库中为某些用户操作建模的最佳方法是什么?假设您可以执行一系列可扩展的操作,例如:登录,注销,个人资料更新和停用等等....
第一种方法将操作作为字符串存储在一列中....
CREATE TABLE user_actions
(
id bigserial NOT NULL,
user_id integer,
created_on timestamp with time zone NOT NULL,
action character varying(20) NOT NULL,
)
或为每个动作创建一个布尔列,在添加新动作时更多,但可能更快更容易搜索......
CREATE TABLE user_actions
(
id bigserial NOT NULL,
user_id integer,
created_on timestamp with time zone NOT NULL,
login boolean NOT NULL,
logout boolean NOT NULL,
profile_update boolean NOT NULL,
profile_deactivated boolean NOT NULL,
)
希望得到您的反馈和建议
答案 0 :(得分:1)
我会把这两个分开。创建另一个表调用它" AVAILABLE_ACTIONS"使用整数键,您可以将其用作USER_ACTIONS表的外键。这样可以提供更好的性能,而不必在每次出现新操作时都发出DDL。