All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m17s
- 合并 customer_account 和 shop_account 路由到统一的 account 接口 - 新增统一认证接口 (auth handler) - 实现越权防护中间件和权限检查工具函数 - 新增操作审计日志模型和服务 - 更新数据库迁移 (版本 39: account_operation_log 表) - 补充集成测试覆盖权限检查和审计日志场景
50 lines
2.9 KiB
SQL
50 lines
2.9 KiB
SQL
-- 创建账号操作审计日志表
|
||
CREATE TABLE tb_account_operation_log (
|
||
id BIGSERIAL PRIMARY KEY,
|
||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||
|
||
-- 操作主体
|
||
operator_id BIGINT NOT NULL, -- 操作人 ID
|
||
operator_type INT NOT NULL, -- 操作人类型 (1=超管 2=平台 3=代理 4=企业)
|
||
operator_name VARCHAR(255) NOT NULL, -- 操作人用户名
|
||
|
||
-- 操作对象
|
||
target_account_id BIGINT, -- 目标账号 ID(可选,删除操作后可能查不到)
|
||
target_username VARCHAR(255), -- 目标账号用户名
|
||
target_user_type INT, -- 目标账号类型
|
||
|
||
-- 操作内容
|
||
operation_type VARCHAR(50) NOT NULL, -- create/update/delete/assign_roles/remove_role
|
||
operation_desc TEXT NOT NULL, -- 操作描述(中文)
|
||
|
||
-- 变更详情(JSON 格式)
|
||
before_data JSONB, -- 变更前数据(update 操作)
|
||
after_data JSONB, -- 变更后数据(create/update 操作)
|
||
|
||
-- 请求上下文
|
||
request_id VARCHAR(255), -- 请求 ID(关联访问日志)
|
||
ip_address VARCHAR(50), -- 操作 IP
|
||
user_agent TEXT -- User-Agent
|
||
);
|
||
|
||
-- 创建索引优化查询性能
|
||
CREATE INDEX idx_account_log_operator ON tb_account_operation_log(operator_id, created_at);
|
||
CREATE INDEX idx_account_log_target ON tb_account_operation_log(target_account_id, created_at);
|
||
CREATE INDEX idx_account_log_created ON tb_account_operation_log(created_at DESC);
|
||
|
||
-- 添加表注释
|
||
COMMENT ON TABLE tb_account_operation_log IS '账号操作审计日志表';
|
||
COMMENT ON COLUMN tb_account_operation_log.operator_id IS '操作人ID';
|
||
COMMENT ON COLUMN tb_account_operation_log.operator_type IS '操作人类型: 1=超级管理员 2=平台用户 3=代理账号 4=企业账号';
|
||
COMMENT ON COLUMN tb_account_operation_log.operator_name IS '操作人用户名';
|
||
COMMENT ON COLUMN tb_account_operation_log.target_account_id IS '目标账号ID';
|
||
COMMENT ON COLUMN tb_account_operation_log.target_username IS '目标账号用户名';
|
||
COMMENT ON COLUMN tb_account_operation_log.target_user_type IS '目标账号类型';
|
||
COMMENT ON COLUMN tb_account_operation_log.operation_type IS '操作类型: create/update/delete/assign_roles/remove_role';
|
||
COMMENT ON COLUMN tb_account_operation_log.operation_desc IS '操作描述(中文)';
|
||
COMMENT ON COLUMN tb_account_operation_log.before_data IS '变更前数据(JSONB格式,用于update操作)';
|
||
COMMENT ON COLUMN tb_account_operation_log.after_data IS '变更后数据(JSONB格式,用于create/update操作)';
|
||
COMMENT ON COLUMN tb_account_operation_log.request_id IS '请求ID,可关联访问日志';
|
||
COMMENT ON COLUMN tb_account_operation_log.ip_address IS '操作来源IP地址';
|
||
COMMENT ON COLUMN tb_account_operation_log.user_agent IS '用户代理(浏览器信息)';
|