ver_00004.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package db
  2. import (
  3. "context"
  4. nameDB "f1-game/internal/name/db"
  5. "fmt"
  6. clog "github.com/cherry-game/cherry/logger"
  7. "go.mongodb.org/mongo-driver/v2/bson"
  8. "go.mongodb.org/mongo-driver/v2/mongo"
  9. )
  10. // ver00004 修复 Marchs
  11. type ver00004 struct {
  12. }
  13. // Version 手动自增,必需唯一
  14. func (ver00004) Version() int32 {
  15. return 4
  16. }
  17. func (ver00004) Enable() bool {
  18. return false
  19. }
  20. func (p ver00004) Execute() bool {
  21. playerCollection := dbComponent.Collection(nameDB.Table_Player)
  22. ctx := context.Background()
  23. pipeline := mongo.Pipeline{
  24. {{Key: "$set", Value: bson.D{{Key: "Data.Map.Marchs", Value: "$Data.Map.Teams"}}}},
  25. {{Key: "$unset", Value: bson.A{"Data.Map.Teams"}}},
  26. }
  27. result, err := playerCollection.UpdateMany(ctx, bson.D{}, pipeline)
  28. if err != nil {
  29. clog.Errorf("[repairPlayerTable] err = %v", err)
  30. return false
  31. }
  32. clog.Infof("%s is ok. result = %v", p.Desc(), result.ModifiedCount)
  33. return true
  34. }
  35. func (p ver00004) Desc() string {
  36. return fmt.Sprintf("[migrator - %d] repair chapter init level", p.Version())
  37. }