feat: add ads/sponsor/captcha modules and polish home & chat UI
This commit is contained in:
@@ -61,7 +61,7 @@ func InitDB(dsn string) error {
|
||||
&Announcement{}, &SitePage{}, &SiteSetting{}, &SiteDailyStats{}, &SiteDailyVisitor{}, &Attachment{}, &UserBoard{}, &LoginLog{},
|
||||
&ChatRoom{}, &ChatRoomMember{}, &ChatMessage{},
|
||||
&PointLedger{}, &PostContentUnlock{}, &PostAttachment{}, &PostAttachmentUnlock{},
|
||||
&PostPollVote{}, &PostLotteryEntry{},
|
||||
&PostPollVote{}, &PostLotteryEntry{}, &Ad{},
|
||||
); err != nil {
|
||||
return fmt.Errorf("自动迁移失败: %w", err)
|
||||
}
|
||||
@@ -78,6 +78,11 @@ func InitDB(dsn string) error {
|
||||
return fmt.Errorf("login_logs 默认值修正失败: %w", err)
|
||||
}
|
||||
|
||||
// 早期 site_settings.value 可能是 varchar(255);广告/赞助商 JSON 会超长
|
||||
if err := prepareSiteSettingValueText(db); err != nil {
|
||||
return fmt.Errorf("site_settings.value 扩容失败: %w", err)
|
||||
}
|
||||
|
||||
// 新表结构就位后删除遗留的明文列
|
||||
if err := dropLegacyRefreshTokenColumn(db); err != nil {
|
||||
return fmt.Errorf("refresh token 旧列清理失败: %w", err)
|
||||
@@ -152,6 +157,28 @@ func prepareAnnouncementPinnedColumn(db *gorm.DB) error {
|
||||
return db.Exec(`ALTER TABLE announcements ADD COLUMN pinned boolean NOT NULL DEFAULT false`).Error
|
||||
}
|
||||
|
||||
// prepareSiteSettingValueText 将 site_settings.value 从 varchar(255) 扩为 text(幂等)
|
||||
func prepareSiteSettingValueText(db *gorm.DB) error {
|
||||
var tableCount int64
|
||||
if err := db.Raw(`SELECT count(1) FROM information_schema.tables WHERE table_name = 'site_settings'`).
|
||||
Scan(&tableCount).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if tableCount == 0 {
|
||||
return nil
|
||||
}
|
||||
var dataType string
|
||||
if err := db.Raw(`SELECT data_type FROM information_schema.columns
|
||||
WHERE table_name = 'site_settings' AND column_name = 'value'`).
|
||||
Scan(&dataType).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if dataType == "" || dataType == "text" {
|
||||
return nil
|
||||
}
|
||||
return db.Exec(`ALTER TABLE site_settings ALTER COLUMN value TYPE text`).Error
|
||||
}
|
||||
|
||||
// prepareRefreshTokenSessionColumns 存量 refresh_tokens 加 logged_in_at / last_used_at:
|
||||
// 先可空加列,用 created_at 回填后再收紧 NOT NULL。
|
||||
func prepareRefreshTokenSessionColumns(db *gorm.DB) error {
|
||||
|
||||
Reference in New Issue
Block a user