From ec1855dfac09d670928bbc591830cb68135f500a Mon Sep 17 00:00:00 2001 From: xinian Date: Mon, 27 Apr 2026 00:54:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=B8=AD=E7=9A=84=20uniqueIndex=20=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/cool/coolconfig/config.go | 2 +- help/server_show冠名索引修复.sql | 7 ++++++- help/初始化SPT配置.sql | 9 +++++++-- modules/config/model/cdk.go | 2 +- modules/config/model/fight_rule.go | 2 +- modules/config/model/peak_tianxuan.go | 4 ++-- modules/config/model/peak_tianxuan_vote.go | 4 ++-- modules/config/model/server_show.go | 4 ++-- modules/config/model/shop.go | 2 +- modules/config/model/sign.go | 6 +++--- modules/config/model/spt.go | 2 +- modules/config/model/tower_110.go | 2 +- modules/player/model/info.go | 2 +- 13 files changed, 29 insertions(+), 19 deletions(-) diff --git a/common/cool/coolconfig/config.go b/common/cool/coolconfig/config.go index 031b474f..b669ee75 100644 --- a/common/cool/coolconfig/config.go +++ b/common/cool/coolconfig/config.go @@ -23,7 +23,7 @@ type sConfig struct { } type ServerList struct { - OnlineID uint32 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"` + OnlineID uint32 `gorm:"column:online_id;comment:'在线ID'" json:"online_id"` //服务器名称Desc Name string `gorm:"comment:'服务器名称'" json:"name"` IP string `gorm:"type:string;comment:'服务器IP'" json:"ip"` diff --git a/help/server_show冠名索引修复.sql b/help/server_show冠名索引修复.sql index 8d449f53..2e8c7743 100644 --- a/help/server_show冠名索引修复.sql +++ b/help/server_show冠名索引修复.sql @@ -13,6 +13,11 @@ DROP INDEX IF EXISTS idx_server_show_server_id; CREATE INDEX IF NOT EXISTS idx_server_show_server_id ON server_show (server_id); -- 保证“一个玩家对一个服务器最多一条” -CREATE UNIQUE INDEX IF NOT EXISTS idx_server_show_server_owner ON server_show (server_id, owner); +ALTER TABLE server_show DROP CONSTRAINT IF EXISTS idx_server_show_server_owner; +DROP INDEX IF EXISTS idx_server_show_server_owner; + +CREATE UNIQUE INDEX IF NOT EXISTS idx_server_show_server_owner +ON server_show (server_id, owner) +WHERE deleted_at IS NULL; COMMIT; diff --git a/help/初始化SPT配置.sql b/help/初始化SPT配置.sql index 051be531..db401baa 100644 --- a/help/初始化SPT配置.sql +++ b/help/初始化SPT配置.sql @@ -19,7 +19,12 @@ CREATE TABLE IF NOT EXISTS config_spt ( description TEXT NOT NULL DEFAULT '' ); -CREATE UNIQUE INDEX IF NOT EXISTS idx_config_spt_task_id ON config_spt(task_id); +ALTER TABLE config_spt DROP CONSTRAINT IF EXISTS idx_config_spt_task_id; +DROP INDEX IF EXISTS idx_config_spt_task_id; + +CREATE UNIQUE INDEX IF NOT EXISTS idx_config_spt_task_id +ON config_spt(task_id) +WHERE deleted_at IS NULL; ALTER TABLE config_spt DROP COLUMN IF EXISTS seat_id; @@ -58,7 +63,7 @@ VALUES (606,'帕多尼',656,1,5,510,'暗黑Ⅷ-Ⅰ门的守护者,浑身充斥着暗黑能量,暗黑能量会随着它的歌神散发出来。',1,''), (607,'加洛德',659,1,5,510,'暗黑Ⅷ-Ⅱ门的守护,暗黑能量的注入,使它的脾气变得暴躁,擅长与对手近身搏斗,浑身的尖刺、催生出的植物都是它进攻的利器。',1,''), (608,'萨多拉尼',661,1,5,510,'暗黑Ⅷ-Ⅲ门的守护,将暗黑能量融入自身,肢体变得非常结实有力,虽然体积很小,但是却拥有了堪比巨龙的神力。',1,'') -ON CONFLICT (task_id) DO UPDATE +ON CONFLICT (task_id) WHERE deleted_at IS NULL DO UPDATE SET title = EXCLUDED.title, pet_id = EXCLUDED.pet_id, diff --git a/modules/config/model/cdk.go b/modules/config/model/cdk.go index f04c820d..38315dbf 100644 --- a/modules/config/model/cdk.go +++ b/modules/config/model/cdk.go @@ -15,7 +15,7 @@ type CDKConfig struct { *cool.Model // 核心字段 - CDKCode string `gorm:"not null;size:16;uniqueIndex:idx_config_gift_cdk_cdk_code,where:deleted_at IS NULL;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"` + CDKCode string `gorm:"not null;size:16;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"` Type uint32 `gorm:"column:type;not null;default:0;comment:'CDK类型:0普通奖励,1服务器冠名'" json:"type" description:"CDK类型"` //cdk可兑换次数,where不等于0 diff --git a/modules/config/model/fight_rule.go b/modules/config/model/fight_rule.go index abc43ed1..06ace59b 100644 --- a/modules/config/model/fight_rule.go +++ b/modules/config/model/fight_rule.go @@ -12,7 +12,7 @@ const TableNameFightRule = "config_fight_rule" type FightRule struct { *cool.Model // 嵌入基础Model(包含主键、创建/更新时间等通用字段) - RuleIdx uint32 `gorm:"not null;uniqueIndex:idx_rule_idx,where:deleted_at IS NULL;comment:'规则索引(300-316)'" json:"rule_idx"` + RuleIdx uint32 `gorm:"not null;comment:'规则索引(300-316)'" json:"rule_idx"` Args []int `gorm:"type:jsonb;comment:'规则参数(JSON数组,对应RuleBase.args)'" json:"args"` Desc string `gorm:"type:varchar(255);default:'';comment:'规则描述'" json:"desc"` } diff --git a/modules/config/model/peak_tianxuan.go b/modules/config/model/peak_tianxuan.go index 984baae5..9fb1b777 100644 --- a/modules/config/model/peak_tianxuan.go +++ b/modules/config/model/peak_tianxuan.go @@ -11,9 +11,9 @@ const ( type PeakTianxuan struct { *BaseConfig - PlayerID uint32 `gorm:"not null;index:idx_peak_tianxuan_player;uniqueIndex:idx_peak_tianxuan_player_pet,where:deleted_at IS NULL;comment:'所属玩家ID'" json:"player_id"` + PlayerID uint32 `gorm:"not null;index:idx_peak_tianxuan_player;comment:'所属玩家ID'" json:"player_id"` DisplayOrder uint32 `gorm:"not null;default:0;comment:'展示顺序'" json:"display_order"` - PetID uint32 `gorm:"not null;uniqueIndex:idx_peak_tianxuan_player_pet,where:deleted_at IS NULL;comment:'天选精灵ID'" json:"pet_id"` + PetID uint32 `gorm:"not null;comment:'天选精灵ID'" json:"pet_id"` PresetName string `gorm:"type:varchar(64);not null;default:'';comment:'预设显示名'" json:"preset_name"` Level uint32 `gorm:"not null;default:100;comment:'预设等级'" json:"level"` Nature uint32 `gorm:"not null;default:0;comment:'预设性格'" json:"nature"` diff --git a/modules/config/model/peak_tianxuan_vote.go b/modules/config/model/peak_tianxuan_vote.go index 0c9aaaaa..a36e3d38 100644 --- a/modules/config/model/peak_tianxuan_vote.go +++ b/modules/config/model/peak_tianxuan_vote.go @@ -11,8 +11,8 @@ const ( type PeakTianxuanVote struct { *cool.Model - WeekIndex uint32 `gorm:"not null;uniqueIndex:idx_peak_tianxuan_vote_week_player,where:deleted_at IS NULL;index:idx_peak_tianxuan_vote_week_pet;comment:'周序号'" json:"week_index"` - PlayerID uint32 `gorm:"not null;uniqueIndex:idx_peak_tianxuan_vote_week_player,where:deleted_at IS NULL;comment:'投票玩家ID'" json:"player_id"` + WeekIndex uint32 `gorm:"not null;index:idx_peak_tianxuan_vote_week_pet;comment:'周序号'" json:"week_index"` + PlayerID uint32 `gorm:"not null;comment:'投票玩家ID'" json:"player_id"` PetID uint32 `gorm:"not null;index:idx_peak_tianxuan_vote_week_pet;comment:'投票精灵ID'" json:"pet_id"` } diff --git a/modules/config/model/server_show.go b/modules/config/model/server_show.go index f5a014a3..46e53d09 100644 --- a/modules/config/model/server_show.go +++ b/modules/config/model/server_show.go @@ -10,9 +10,9 @@ const TableNameServerShow = "server_show" // ServerShow 绑定服务器展示信息(冠名、属主、到期时间)。 type ServerShow struct { *cool.Model - ServerID uint32 `gorm:"column:server_id;comment:'服务器ID';index:idx_server_show_server_id;uniqueIndex:idx_server_show_server_owner,where:deleted_at IS NULL" json:"server_id"` + ServerID uint32 `gorm:"column:server_id;comment:'服务器ID';index:idx_server_show_server_id" json:"server_id"` Name string `gorm:"comment:'服务器展示名'" json:"name"` - Owner uint32 `gorm:"comment:'服务器属主';uniqueIndex:idx_server_show_server_owner,where:deleted_at IS NULL" json:"owner"` + Owner uint32 `gorm:"comment:'服务器属主'" json:"owner"` ExpireTime time.Time `gorm:"column:expire_time;default:0;comment:'展示到期时间'" json:"expire_time"` } diff --git a/modules/config/model/shop.go b/modules/config/model/shop.go index 1d74ca5a..e80104cf 100644 --- a/modules/config/model/shop.go +++ b/modules/config/model/shop.go @@ -17,7 +17,7 @@ type ShopConfig struct { ProductType uint32 `gorm:"not null;default:0;comment:'商品类型'" json:"product_type" description:"商品类型"` //商品ID - ProductID int64 `gorm:"not null;uniqueIndex:idx_config_shop_product_id,where:deleted_at IS NULL;comment:'商品ID'" json:"product_id" description:"商品ID"` + ProductID int64 `gorm:"not null;comment:'商品ID'" json:"product_id" description:"商品ID"` // 价格信息 -1代表不允许购买,0表示不支持购买 SeerdouPrice int32 `gorm:"not null;default:0;comment:'骄阳豆价格'" json:"seerdou_price" description:"骄阳豆价格"` diff --git a/modules/config/model/sign.go b/modules/config/model/sign.go index d98e3238..ea099469 100644 --- a/modules/config/model/sign.go +++ b/modules/config/model/sign.go @@ -12,9 +12,9 @@ const ( // SignIn 签到阶段配置表。 type SignIn struct { *BaseConfig - SignType uint32 `gorm:"not null;default:1;uniqueIndex:idx_sign_type_stage,where:deleted_at IS NULL;comment:'签到类别(1-累计 2-连续)'" json:"sign_type"` - StageDays uint32 `gorm:"not null;default:1;uniqueIndex:idx_sign_type_stage,where:deleted_at IS NULL;comment:'签到阶段天数(0/1/3/7/14/30)'" json:"stage_days"` - CdkID uint32 `gorm:"not null;uniqueIndex:idx_config_sign_in_cdk_id,where:deleted_at IS NULL;comment:'绑定的CDK配置ID'" json:"cdk_id"` + SignType uint32 `gorm:"not null;default:1;comment:'签到类别(1-累计 2-连续)'" json:"sign_type"` + StageDays uint32 `gorm:"not null;default:1;comment:'签到阶段天数(0/1/3/7/14/30)'" json:"stage_days"` + CdkID uint32 `gorm:"not null;comment:'绑定的CDK配置ID'" json:"cdk_id"` } func (*SignIn) TableName() string { diff --git a/modules/config/model/spt.go b/modules/config/model/spt.go index 4e5d0f6f..cf56d9f2 100644 --- a/modules/config/model/spt.go +++ b/modules/config/model/spt.go @@ -10,7 +10,7 @@ const ( type SptConfig struct { *BaseConfig - TaskID uint32 `gorm:"not null;uniqueIndex:idx_config_spt_task_id,where:deleted_at IS NULL;comment:'SPT任务ID'" json:"task_id" description:"SPT任务ID"` + TaskID uint32 `gorm:"not null;comment:'SPT任务ID'" json:"task_id" description:"SPT任务ID"` Title string `gorm:"type:varchar(64);not null;default:'';comment:'SPT名字'" json:"title" description:"SPT名字"` PetID uint32 `gorm:"not null;default:0;comment:'SPT精灵ID'" json:"pet_id" description:"SPT精灵ID"` Online int32 `gorm:"not null;default:1;comment:'是否开放(1开放/0未开放)'" json:"online" description:"是否开放"` diff --git a/modules/config/model/tower_110.go b/modules/config/model/tower_110.go index fbb1a8cc..7dec992a 100644 --- a/modules/config/model/tower_110.go +++ b/modules/config/model/tower_110.go @@ -14,7 +14,7 @@ const ( type BaseTowerConfig struct { *BaseConfig Name string `gorm:"type:varchar(100);default:'';comment:'name'" json:"name" description:"name"` - TowerLevel uint32 `gorm:"not null;default:0;uniqueIndex:,where:deleted_at IS NULL;comment:'tower level'" json:"tower_level"` + TowerLevel uint32 `gorm:"not null;default:0;comment:'tower level'" json:"tower_level"` BossIds []uint32 `gorm:"type:jsonb;comment:'boss ids'" json:"boss_ids"` } diff --git a/modules/player/model/info.go b/modules/player/model/info.go index 906e4310..32ddbdc0 100644 --- a/modules/player/model/info.go +++ b/modules/player/model/info.go @@ -13,7 +13,7 @@ const TableNamePlayerInfo = "player_info" type Player struct { *cool.Model - PlayerID uint64 `gorm:"not null;uniqueIndex:idx_player_info_player_id,where:deleted_at IS NULL;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"` + PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"` LastResetTime *gtime.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务 WeekLastResetTime *gtime.Time `struc:"skip" json:"week_last_reset_time"` Data PlayerInfo `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`