ver_00002.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package db
  2. import (
  3. cherryApp "f1-game/internal/cherry_app"
  4. "fmt"
  5. clog "github.com/cherry-game/cherry/logger"
  6. )
  7. // ver00002 补充系统城池
  8. type ver00002 struct {
  9. }
  10. // Version 手动自增,必需唯一
  11. func (ver00002) Version() int32 {
  12. return 2
  13. }
  14. func (ver00002) Enable() bool {
  15. return false
  16. }
  17. func (p ver00002) Execute() bool {
  18. clog.Infof("Execute %v, nodeID = %s", p.Version(), cherryApp.NodeID())
  19. // nodeTable, _ := GetMapNodeTableFromDB(capp.NodeID())
  20. // mapCastleCollection := dbComponent.DB().Collection(nameDB.Table_MapCastle)
  21. // mapCastleTables := []*MapCastleTable{}
  22. // for _, castleRow := range data.MapCastle.List() {
  23. // var (
  24. // x = castleRow.Point.X
  25. // y = castleRow.Point.Y
  26. // offsetPoints = data.MapObject.GetOffsetPoints(castleRow.ConfigID, x, y)
  27. // table = NewMapCastleTable(nodeTable.newGUID(), capp.NodeID(), x, y, castleRow.ID, offsetPoints...)
  28. // )
  29. // mapCastleTables = append(mapCastleTables, table)
  30. // }
  31. // _, err := mapCastleCollection.InsertMany(context.Background(), mapCastleTables)
  32. // if err != nil {
  33. // clog.Fatalf("[migrator - %d] insert map castle table error: %v", p.Version(), err)
  34. // }
  35. // mapCastleBaseCollection := dbComponent.DB().Collection(nameDB.Table_MapCastleBase)
  36. // mapCastleBaseTables := []*MapCastleBaseTable{}
  37. // for _, castleRow := range data.MapCastleBase.List() {
  38. // var (
  39. // x = castleRow.Point.X
  40. // y = castleRow.Point.Y
  41. // offsetPoints = data.MapObject.GetOffsetPoints(constant.MapTile_CastleBase, x, y)
  42. // table = NewMapCastleBaseTable(nodeTable.newGUID(), capp.NodeID(), x, y, castleRow.BaseID, offsetPoints...)
  43. // )
  44. // mapCastleBaseTables = append(mapCastleBaseTables, table)
  45. // }
  46. // _, err = mapCastleBaseCollection.InsertMany(context.Background(), mapCastleBaseTables)
  47. // if err != nil {
  48. // clog.Fatalf("[migrator - %d] insert map castle base table error: %v", p.Version(), err)
  49. // }
  50. // tableBytes, _ := bson.Marshal(nodeTable)
  51. // update := bson.D{{Key: "$set", Value: bson.Raw(tableBytes)}}
  52. // filter := bson.M{
  53. // "_id": nodeTable.PrimaryValue(), // 利用自带的_id主键进行条件过滤
  54. // }
  55. // _, err = dbComponent.DB().
  56. // Collection(nodeTable.TableName()).
  57. // UpdateOne(context.Background(), filter, update, options.UpdateOne().SetUpsert(true))
  58. // if err != nil {
  59. // clog.Fatalf("[migrator - %d] update node table error: %v", p.Version(), err)
  60. // }
  61. return true
  62. }
  63. func (p ver00002) Desc() string {
  64. return fmt.Sprintf("[migrator - %d] insert map castle", p.Version())
  65. }