data/config/environment.yaml 包含运行环境相关的配置,例如数据库、Redis、Elasticsearch 等外部服务的连接地址。第一次运行前,请根据该目录下的 environment.yaml.example 创建 environment.yaml 并更新其中的配置。
一般情况下,登录状态的验证在中间件中完成,无需额外校验。通过 api.GetAuthorizedUser 函数直接获取当前登录用户。
user := api.GetAuthorizedUser(c) // c 为 *gin.Context
// 如果 API 包含了 `RequireAuthorizationMiddleware` 中间件(绝大多数 API 都是如此),返回值不可能为 `nil`,可直接读取:
// user.Uid, user.UserName, ...
// 如果 API 只包含 `CheckAuthorizationMiddleware` 中间件,需要判断 `user`` 是否为 `nil` 确定登录状态,并根据登录状态返回不同的数据。
user := api.GetAuthorizedUser(c) // c 为 *gin.Context
canView := user.GetPermissions().CanView(fid) // 允许访问 fid 对应的版块
canPostThread := user.GetPermissions().CanPostThread(fid) // 允许发表主题
canPostReply := user.GetPermissions().CanPostReply(fid) // 允许发表回复
availableFids := user.GetPermissions().AvailableFids // 可以访问的所有版块
为方便本地开发过程中测试 API,在 data/config/environment.yaml 中的 app 部分,可以将 dev_impersonate_user_id 属性设置为自己的 UID,调用 API 测试时无需再传入认证相关的参数,直接以该 UID 的身份操作(认证相关 API 除外)。
请勿在服务器上使用该属性。另外当 mode 不为 dev 时该属性不起作用。
- CheckAuthorizationMiddleware:检查用户登录状态,但不强制要求登录。如果已登录,会在 gin.Context 中保存登录信息。
- RequireAuthorizationMiddleware:需要在
CheckAuthorizationMiddleware之后使用,检查CheckAuthorizationMiddleware解析的用户登录状态,如果未登录直接终止请求。
这两个中间件的使用参见 routes/Routes.go,通常无需特别考虑这个问题。
从 eb5976b 起,已升级为 Gorm v2 版本。请充分利用 Gorm v2 的各种特性优雅地编写查询语句。
**特别注意:Discuz! 部分字段末尾仍有一个分隔符,例如 dis_forum_polloption.voterids,在更新时仍要保留末尾的分隔符,否则会导致数据错误。**考虑实现一个新的 Serializer 处理这种情况。
目前实现了 CommaSeparatedStringsSerializer、TabSeparatedStringsSerializer 与 TabSeparatedIntegersSerializer,数据库中制表符分隔的字段可以用 csv_string/tsv_string/tsv_int 序列化和反序列化。例如:
type SomeModel struct {
// 注意 gorm 标签中的 serializer 属性。
Moderators []string `gorm:"serializer:tsv_string"`
ExtGroupIds []uint32 `gorm:"serializer:tsv_int"`
}
var data SomeModel
err = db.First(&data).Error
// data.Moderators/ExtGroupIds 可直接读取,无需再进行字符串分割、转换为整数等操作。使用 air 可以在代码修改后自动编译并重新运行,提高开发效率。
docker compose -f compose-air.yml up --build使用 delve 并配合前端 IDE 插件(例如 Visual Studio Code + Go)进行单步调试。
Discuz! 数据库参考:https://addon.dismall.com/library/database/x3/x3_index.html
ALTER TABLE dis_forum_post DROP column quanstatus, DROP column reply, ADD column lastedit_id INT unsigned NOT NULL DEFAULT 0;
ALTER TABLE dis_forum_post_2 DROP column quanstatus, DROP column reply, ADD column lastedit_id INT unsigned NOT NULL DEFAULT 0;
ALTER TABLE dis_forum_memberrecommend DROP COLUMN username, ADD COLUMN attitude tinyint(1) unsigned NOT NULL DEFAULT 255;
ALTER TABLE dis_forum_forum MODIFY posts int unsigned NOT NULL DEFAULT 0;
ALTER TABLE dis_home_notification MODIFY from_id int(10) unsigned NOT NULL DEFAULT 0;
-- 20240225 IP 字段扩容
ALTER TABLE dis_forum_post_2 MODIFY useip varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', LOCK SHARED;
-- useip='火星'
update dis_forum_post set useip='Mars' where pid in ( 13362995, 13362985, 13362925, 13362962, 13362964, 13362971, 13362976, 13362932, 13362994, 666801, 13362954, 13362920, 13362943, 13362959, 13362921, 13362930, 13362937, 13362938, 13362979, 13362984, 13362993, 13362924, 13362950, 13362965, 13362923, 13362966, 13362970, 13362926, 13362929, 13362931, 13362933, 13362934, 13362935, 13362956, 13362963, 13362969, 13362927, 13362939, 13362953, 13362944, 13362955, 13362961, 13362972, 13362986, 13362922, 13362940, 13362942, 13362947, 13362973, 13362978, 13362980, 13362982, 13362919, 13362936, 13362941, 13362945, 13362946, 13362949, 13362952, 13362958, 13362974, 13362989, 13362990, 13362991, 13362948, 13362951, 13362957, 13362968, 13362981, 667102, 13362960, 13362967, 13362975, 13362977, 13362983, 13362987, 13362988, 13362992, 667103, 667104);
ALTER TABLE dis_forum_post MODIFY `useip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', LOCK SHARED;
-- Query OK, 32870821 rows affected (24 min 32.801 sec)
ALTER TABLE dis_forum_postcomment MODIFY `useip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', LOCK SHARED;
ALTER TABLE dis_common_member_status MODIFY `regip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', MODIFY `lastip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', LOCK SHARED;
ALTER TABLE dis_common_member_status_archive MODIFY `regip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', MODIFY `lastip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', LOCK SHARED;
-- end of 20240225 IP 字段扩容
-- 20240428 dis_ucenter_members `regip` 扩容
ALTER TABLE dis_ucenter_members MODIFY `regip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', LOCK SHARED;
-- 20240503 `email` 字段扩容
alter table dis_ucenter_members modify `email` varchar(64) character set ascii NOT NULL DEFAULT '', lock shared;
alter table dis_common_member modify `email` varchar(64) character set ascii NOT NULL DEFAULT '', lock shared;
alter table dis_common_member_archive modify `email` varchar(64) character set ascii NOT NULL DEFAULT '', lock shared;
CREATE TABLE newbbs_forum_post_history (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`pid` int(10) unsigned NOT NULL,
`subject` varchar(80) NOT NULL DEFAULT '',
`message` longtext NOT NULL DEFAULT '',
`usesig` tinyint(1) NOT NULL DEFAULT 0,
`format` tinyint(1) NOT NULL DEFAULT 0,
`smileyoff` tinyint(1) NOT NULL DEFAULT 0,
`extra` longtext NOT NULL DEFAULT '',
`authorid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`dateline` int(10) unsigned NOT NULL DEFAULT 0,
`useip` varchar(45) CHARACTER SET ascii NOT NULL DEFAULT ''
`flags` mediumint(8) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `displayorder` (`pid`, `dateline`)
) CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 保存已删除的附件
CREATE TABLE `newbbs_forum_attachment_deleted` (
`aid` mediumint(8) unsigned NOT NULL,
`tid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`pid` int(10) unsigned NOT NULL DEFAULT 0,
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`dateline` int(10) unsigned NOT NULL DEFAULT 0,
`filename` varchar(255) NOT NULL DEFAULT '',
`filesize` int(10) unsigned NOT NULL DEFAULT 0,
`attachment` varchar(255) NOT NULL DEFAULT '',
`remote` tinyint(1) unsigned NOT NULL DEFAULT 0,
`description` varchar(255) NOT NULL,
`readperm` tinyint(3) unsigned NOT NULL DEFAULT 0,
`price` smallint(6) unsigned NOT NULL DEFAULT 0,
`isimage` tinyint(1) NOT NULL DEFAULT 0,
`width` smallint(6) unsigned NOT NULL DEFAULT 0,
`thumb` tinyint(1) unsigned NOT NULL DEFAULT 0,
`picid` mediumint(8) NOT NULL DEFAULT 0,
`downloads` mediumint(8) NOT NULL DEFAULT 0,
PRIMARY KEY (`aid`),
KEY `tid` (`tid`),
KEY `pid` (`pid`),
KEY `uid` (`uid`)
)
-- 上线前忘记调整 newbbs_forum_post_history 表中的 useip 字段了!
alter table newbbs_forum_post_history modify useip varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', LOCK SHARED;
-- 举报用户较多的帖子自动屏蔽功能需要新增字段和表。
alter table dis_common_report add column uids mediumtext NOT NULL default '', lock shared;
CREATE TABLE `dis_forum_post_report` (
`pid` int(10) unsigned NOT NULL,
`reportid` mediumint(8) unsigned NOT NULL,
`dateline` int(10) unsigned NOT NULL DEFAULT 0,
`status` int(10) unsigned NOT NULL DEFAULT 0,
`opuid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`opname` varchar(15) NOT NULL DEFAULT '',
`optime` int(10) unsigned NOT NULL DEFAULT 0,
`fid` mediumint(8) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`pid`),
KEY `status` (`status`)
);
-- 抢楼帖增加额外信息
ALTER TABLE dis_forum_threadrush ADD COLUMN `newbbsext` MEDIUMTEXT NOT NULL DEFAULT '', LOCK SHARED;
-- dis_forum_ratelog reason 字段扩容
ALTER TABLE dis_forum_ratelog MODIFY `reason` VARCHAR(100) NOT NULL DEFAULT '', LOCK SHARED;
CREATE TABLE `newbbs_rush_reply_credit_awards` (
`tid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`extcredits1` int(10) NOT NULL DEFAULT 0,
`extcredits2` int(10) NOT NULL DEFAULT 0,
`extcredits3` int(10) NOT NULL DEFAULT 0,
`extcredits4` int(10) NOT NULL DEFAULT 0,
`extcredits5` int(10) NOT NULL DEFAULT 0,
`extcredits6` int(10) NOT NULL DEFAULT 0,
`extcredits7` int(10) NOT NULL DEFAULT 0,
`extcredits8` int(10) NOT NULL DEFAULT 0,
PRIMARY KEY (`tid`, `uid`)
);
CREATE TABLE `newbbs_log_rate` (
`pid` int(10) unsigned NOT NULL DEFAULT 0,
`tid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`fid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`authorid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`type` tinyint unsigned NOT NULL DEFAULT 0,
`extcredits` tinyint(1) unsigned NOT NULL DEFAULT 0,
`dateline64` bigint unsigned NOT NULL DEFAULT 0,
`score` smallint(6) NOT NULL DEFAULT 0,
`reason` varchar(100) NOT NULL DEFAULT '',
`notify` tinyint unsigned NOT NULL DEFAULT 0,
KEY `dateline64` (`dateline64`),
KEY `uid` (`uid`),
KEY `fid` (`fid`, `dateline64`)
);
-- 在线时间字段扩容
alter table dis_common_member_count_archive modify oltime mediumint(8) unsigned NOT NULL DEFAULT 0, lock shared;
alter table dis_common_member_count modify oltime mediumint(8) unsigned NOT NULL DEFAULT 0, lock shared;
-- 邮箱验证
CREATE TABLE `newbbs_email_verify` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(64) character set ascii NOT NULL DEFAULT '',
`secret` varchar(44) character set ascii NOT NULL DEFAULT '',
`ip` varchar(45) character set ascii NOT NULL DEFAULT '',
`sendtime` BIGINT unsigned NOT NULL,
`verifytime` BIGINT unsigned NOT NULL,
`emailretry` tinyint unsigned NOT NULL DEFAULT 0,
`verifyretry` tinyint unsigned NOT NULL DEFAULT 0,
`uidlist` mediumtext NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `sendtime`(`sendtime`),
UNIQUE KEY (`secret`) USING HASH
);
-- 实名换绑表更新
ALTER TABLE `dis_star_alumni_bind_log` ADD COLUMN `dateline64` bigint unsigned NOT NULL DEFAULT 0, LOCK SHARED;
ALTER TABLE `dis_star_alumni_bind_log` DROP INDEX `uniq_student_id`, LOCK SHARED;
ALTER TABLE `dis_star_alumni_bind_log` ADD INDEX `new_student_id` (`student_id`), LOCK SHARED;
ALTER TABLE `dis_star_alumni_bind_log` ADD INDEX `old_student_id` (`under_graduate_student_id`), LOCK SHARED;
RENAME TABLE `dis_star_alumni_bind_log` TO `newbbs_log_user_renew`;
ALTER TABLE `newbbs_log_user_renew` CHANGE `student_id` `new_student_id` varchar(63) DEFAULT NULL, LOCK SHARED;
ALTER TABLE `newbbs_log_user_renew` CHANGE `under_graduate_student_id` `old_student_id` varchar(63) DEFAULT NULL, LOCK SHARED;
ALTER TABLE `newbbs_log_user_renew` CHANGE `under_graduate_ids` `renewed_uids` varchar(255) DEFAULT NULL, LOCK SHARED;
ALTER TABLE `dis_common_member` ADD COLUMN `settingver` int unsigned NOT NULL DEFAULT 0, LOCK SHARED;
ALTER TABLE `dis_common_member_archive` ADD COLUMN `settingver` int unsigned NOT NULL DEFAULT 0, LOCK SHARED;
-- 20250902 IP 字段扩容
alter table dis_common_failedlogin modify ip varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', lock shared;
alter table dis_ucenter_failedlogins modify ip varchar(45) CHARACTER SET ascii NOT NULL DEFAULT '', lock shared;
-- 20250904
alter online table dis_ucenter_notelist modify column `app4` tinyint(4) NOT NULL default 0;
alter online table dis_ucenter_notelist modify column `app1` tinyint(4) NOT NULL default 0;
-- 2025 迎新兑奖
CREATE TABLE `newbbs_ext_freshman_code_2025` (
`code` char(8) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`studentID` varchar(63) NOT NULL DEFAULT '',
`water` int(10) NOT NULL DEFAULT 0,
`gift` int unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`code`),
KEY `uid` (`uid`),
KEY `studentID` (`studentID`)
);
CREATE TABLE `newbbs_ext_freshman_validation_2025` (
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`studentID` varchar(63) NOT NULL,
`ip` varchar(45) character set ascii NOT NULL DEFAULT '',
`code` char(32) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`status` tinyint unsigned NOT NULL DEFAULT 0,
`dateline64` bigint unsigned NOT NULL DEFAULT 0,
KEY `uid` (`uid`),
KEY `studentID` (`studentID`)
);
CREATE TABLE `newbbs_ext_freshman_prize_2025` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(256) NOT NULL DEFAULT '',
`total` int unsigned NOT NULL DEFAULT 0,
`remaining` int unsigned NOT NULL DEFAULT 0,
`probability1` smallint unsigned NOT NULL DEFAULT 0,
`probability2` smallint unsigned NOT NULL DEFAULT 0,
`probability3` smallint unsigned NOT NULL DEFAULT 0,
`claimtext` varchar(256) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
);
-- 允许短时间内取消或更新回复的支持/反对。
ALTER TABLE dis_forum_hotreply_member ADD COLUMN `dateline` int(10) unsigned NOT NULL DEFAULT 0, LOCK SHARED;
-- 2025 十八周年庆
CREATE TABLE `newbbs_ext_anniversary_code_2025` (
`code` char(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`code2` char(10) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`studentID` varchar(63) NOT NULL DEFAULT '',
`water` int(10) NOT NULL DEFAULT 0,
`gift` int unsigned NOT NULL DEFAULT 0,
`claimed` tinyint unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`code`),
UNIQUE KEY (`code2`),
KEY `uid` (`uid`),
KEY `studentID` (`studentID`)
);
CREATE TABLE `newbbs_ext_anniversary_validation_2025` (
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`studentID` varchar(63) NOT NULL,
`ip` varchar(45) character set ascii NOT NULL DEFAULT '',
`code` char(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`method` tinyint unsigned NOT NULL DEFAULT 0,
`status` tinyint unsigned NOT NULL DEFAULT 0,
`dateline64` bigint unsigned NOT NULL DEFAULT 0,
KEY `uid` (`uid`),
KEY `studentID` (`studentID`)
);
CREATE TABLE `newbbs_ext_anniversary_prize_2025` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(256) NOT NULL DEFAULT '',
`total` int unsigned NOT NULL DEFAULT 0,
`remaining` int unsigned NOT NULL DEFAULT 0,
`probability1` smallint unsigned NOT NULL DEFAULT 0,
`probability2` smallint unsigned NOT NULL DEFAULT 0,
`probability3` smallint unsigned NOT NULL DEFAULT 0,
`limitperuser` tinyint unsigned NOT NULL DEFAULT 0,
`claimtext` varchar(256) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
);
CREATE TABLE `newbbs_ext_anniversary_prize_claim_2025` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`adminuid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`code` char(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`operation` tinyint unsigned NOT NULL DEFAULT 0,
`dateline64` bigint unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
KEY `adminuid` (`adminuid`),
KEY `code` (`code`)
);
--- 扩展功能公用
CREATE TABLE `newbbs_ext_common_settings` (
`ext` VARCHAR(32) NOT NULL,
`key` VARCHAR(256) NOT NULL,
`value` MEDIUMTEXT NOT NULL,
PRIMARY KEY (`ext`, `key`)
);
-- 以上改动已在河畔生产环境中执行。
CREATE TABLE `newbbs_student_map` (
`old_student_id` varchar(63) NOT NULL DEFAULT '',
`new_student_id` varchar(63) NOT NULL DEFAULT '',
KEY (`old_student_id`),
);
-- WebAuthn
CREATE TABLE `newbbs_webauthn_identity` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`uid` mediumint(8) unsigned NOT NULL DEFAULT 0,
`dateline64` bigint unsigned NOT NULL DEFAULT 0,
`nonce` varchar(24) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`status` tinyint unsigned NOT NULL DEFAULT 0,
`useragent` varchar(512) NOT NULL DEFAULT '',
`devicename` varchar(128) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
)
-- 注册用户审核
CREATE TABLE `newbbs_pending_new_members` (
`username` char(15) NOT NULL DEFAULT '',
`password` char(32) NOT NULL DEFAULT '',
`email` varchar(64) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '',
`regip` varchar(45) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '',
`regdate` int(10) unsigned NOT NULL DEFAULT 0,
`salt` char(6) NOT NULL,
`status` tinyint unsigned NOT NULL DEFAULT 0,
KEY `status_username` (`status`, `username`)
);
-- 好友请求附言字段扩容
ALTER TABLE dis_home_friend_request MODIFY `note` varchar(255) NOT NULL DEFAULT '', LOCK SHARED;
- 删除 dis_forum_post 中的老旧字段,增加 lastedit_id 字段,与编辑历史表关联。
quanstatus 可能是以前某个 Discuz! 插件增加的,在 old-bbs 中完全找不到痕迹。reply 字段不知道是什么时候增加的,可能与回复信息有关,现有的数据也很奇怪,但应该也不是 Discuz! 或现在正在运行的插件所需要的。原本计划改动的 replies 与 reply_to 字段放在 dis_forum_post 表中不太合适,并且当前的功能计划表中未涉及,待未来详细研究之后再考虑是否实现以及数据表的设计,
-
删除 dis_forum_memberrecommend 中的 username 字段,增加 attitude 字段。
-
部分字段扩容:dis_forum_forum.posts、dis_home_notification.from_id;部分 IP 字段扩容支持 IPv6;Email 字段扩容。
-
dis_common_report 增加字段。
-
dis_forum_ratelog reason 字段扩容
- newbbs_forum_post_history 保存帖子编辑历史。
- dis_forum_post_report 保存帖子举报信息。
- newbbs_rush_reply_credit_awards 抢楼帖积分奖励。s
- newbbs_log_rate 评分日志。
CREATE TABLE `newbbs_ext_bet_category` (
`id` smallint unsigned NOT NULL AUTO_INCREMENT,
`name` VARCHAR(32) NOT NULL,
`flags` INT unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
);
CREATE TABLE `newbbs_ext_bet_competition` (
`id` mediumint unsigned NOT NULL AUTO_INCREMENT,
`creator` mediumint unsigned NOT NULL,
`category` smallint unsigned NOT NULL DEFAULT 0,
`title` VARCHAR(128) NOT NULL,
`description` MEDIUMTEXT NOT NULL DEFAULT '',
`option1` VARCHAR(128) NOT NULL DEFAULT '',
`option2` VARCHAR(128) NOT NULL DEFAULT '',
`option3` VARCHAR(128) NOT NULL DEFAULT '',
`rate1` DOUBLE NOT NULL DEFAULT 0,
`rate2` DOUBLE NOT NULL DEFAULT 0,
`rate3` DOUBLE NOT NULL DEFAULT 0,
`taxrate` DOUBLE NOT NULL DEFAULT 0,
`starttime64` BIGINT unsigned NOT NULL DEFAULT 0,
`endtime64` BIGINT unsigned NOT NULL DEFAULT 0,
`result` tinyint unsigned NOT NULL DEFAULT 0,
`flags` INT unsigned NOT NULL DEFAULT 0,
`participants` INT unsigned NOT NULL DEFAULT 0,
`totalincome` INT unsigned NOT NULL DEFAULT 0,
`totalexpense` INT unsigned NOT NULL DEFAULT 0,
`extra` MEDIUMTEXT NOT NULL DEFAULT '',
PRIMARY KEY(`id`)
);
CREATE TABLE `newbbs_ext_bet_amount` (
`competition` mediumint unsigned NOT NULL,
`uid` mediumint unsigned NOT NULL,
`option` tinyint unsigned NOT NULL,
`amount` int unsigned NOT NULL,
`wincredits` int unsigned NOT NULL,
`dateline64` BIGINT unsigned NOT NULL,
KEY competition(`competition`),
KEY uid(`uid`, `dateline64`)
);
CREATE TABLE `newbbs_ext_bet_subscription` (
`category` smallint unsigned NOT NULL,
`uid` mediumint unsigned NOT NULL,
KEY category(`category`),
KEY uid(`uid`)
);
- Uid/Tid/Pid/Fid uint32
- Dateline/Lastpost/Timestamp int64 (数据库中目前为 32 位,考虑到未来的 2038 年问题、提高时间戳精度采用 64 位)
一般地,数据库中不超过 32 位的整数、并且未来也不可能超出 32 位表达范围的字段使用 int32/uint32(数据库中定义为无符号整形的应当使用无符号整型),只有 8 位的整数视情况使用 int8/uint8 或 bool(确认取值只有 0、1 两种时才能使用 bool)。不使用 int16/uint16。时间戳使用 int64。
生产服务器上根据实际需要将运行三种不同策略的 Redis 实例:
CacheRedis,保存经常会用到的缓存数据,并设置内存占用上限,其中的内容随时可能丢失。(maxmemory-policy allkeys-lfu)MemoryRedis,保存在线状态、锁、临时认证信息等暂态运行时信息,只有过期时才会消失,服务器重启不保留数据。PersistentRedis,保存经常用到且更新频繁的统计、配置数据,定时保存到磁盘,服务器重启后仍然保留。
本地运行时,为了方便可以只设置 environment.yaml 中的 redis 部分,只启动一个 Redis 实例。
开发过程中,应根据需求选择合适的 Redis 实例读取、写入数据;Redis 的 Key 应确保唯一,即使存储在不同 Redis 实例中。
以下内容有待进一步整理更新,可能与实际不符。
member__field_forum medals字段有过期时间