Fix legacy unit schema migration
Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -49,6 +49,9 @@ func BuildRewardResp(ss *session.Session, playRewardReq liveschema.RewardReq, is
|
||||
return liveschema.RewardResp{}, errors.New("live progress not found")
|
||||
}
|
||||
_, deckInfo := ss.GetDeckInfo(progress.DeckID)
|
||||
if deckInfo == nil {
|
||||
return liveschema.RewardResp{}, errors.New("deck info not found")
|
||||
}
|
||||
deckInfo.LiveDifficultyID = difficultyID
|
||||
|
||||
unitsList := []liveschema.PlayRewardUnitList{}
|
||||
|
||||
@@ -188,12 +188,20 @@ func (ss *Session) GetLiveInfo(LiveDifficultyID int) (bool, *liveschema.LiveInfo
|
||||
}
|
||||
|
||||
func (ss *Session) GetDeckInfo(deckID int) (bool, *liverecordschema.DeckInfo) {
|
||||
if ss.UserEng == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 卡片信息
|
||||
totalHp, totalSmile, totalCute, totalCool := 0, 0, 0, 0
|
||||
unitData := []liverecordschema.UnitList{}
|
||||
units := ss.GetUserDeckUnit(deckID)
|
||||
for _, u := range units {
|
||||
_, uData := ss.GetUnitInfo(u.UnitID)
|
||||
has, uData := ss.GetUnitInfo(u.UnitID)
|
||||
if !has || uData == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
tempUnitData := liverecordschema.UnitList{
|
||||
UnitID: u.UnitID,
|
||||
Position: u.Position,
|
||||
@@ -225,10 +233,16 @@ func (ss *Session) GetDeckInfo(deckID int) (bool, *liverecordschema.DeckInfo) {
|
||||
|
||||
// 技能宝石信息
|
||||
skillData := ss.GetUserUnitSkillEquipID(u.UnitOwningUserID)
|
||||
if ss.UserEng == nil {
|
||||
return false, nil
|
||||
}
|
||||
tempUnitData.RemovableSkillIds = skillData
|
||||
|
||||
// 饰品信息
|
||||
has, accessoryData := ss.GetUserAccessoryInfoByUnitOwningUserID(u.UnitOwningUserID)
|
||||
if ss.UserEng == nil {
|
||||
return false, nil
|
||||
}
|
||||
if has {
|
||||
tempUnitData.AccessoryInfo = accessoryData
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ func (ss *Session) GetBasicUnitInfo() *xorm.Session {
|
||||
}
|
||||
|
||||
func (ss *Session) GetUnitInfo(unitID int) (bool, *unitmodel.CommonUnitData) {
|
||||
if ss.UserEng == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
unitInfo := unitmodel.CommonUnitData{}
|
||||
has, err := ss.UserEng.Table(new(unitmodel.CommonUnitData)).
|
||||
Where("unit_id = ?", unitID).Get(&unitInfo)
|
||||
|
||||
@@ -78,6 +78,12 @@ func ForceAllUsersRelogin() {
|
||||
}
|
||||
}
|
||||
|
||||
func MigrateLegacyUnitTables() {
|
||||
if err := db.UserEng.Sync2(new(unitmodel.CommonUnitData), new(usermodel.UserUnitData)); err != nil {
|
||||
log.Fatalln("迁移卡片历史数据表失败:", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
type accessoryOwningMapRow struct {
|
||||
AccessoryOwningUserID int `xorm:"accessory_owning_user_id"`
|
||||
AccessoryID int `xorm:"accessory_id"`
|
||||
|
||||
@@ -3,6 +3,7 @@ package startup
|
||||
func StartUp() {
|
||||
CreateTables()
|
||||
LoadUnitData()
|
||||
MigrateLegacyUnitTables()
|
||||
CreateDefaultUser()
|
||||
EnsureDefaultFriends()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user