feat: 归档旧迁移文件,创建初始化数据迁移和重置脚本

This commit is contained in:
2026-04-14 11:24:35 +08:00
parent c35542f911
commit 5e9e41db21
231 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
-- 创建账号操作审计日志表
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 '用户代理(浏览器信息)';