Skip to content

Commit

Permalink
Update presence_change DB migration for proto marshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Nov 21, 2024
1 parent 082224c commit 083ab63
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion migrations/v0.5.6/migrate-presence-change.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ package v056

import (
"context"
"encoding/json"
"fmt"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"

"github.com/yorkie-team/yorkie/pkg/document/innerpresence"
"github.com/yorkie-team/yorkie/server/backend/database"
)

// validatePresenceChangeMigration validates if all string presence changes are properly migrated
Expand Down Expand Up @@ -75,11 +79,21 @@ func processMigrationBatchPresence(
},
})
} else {
p := &innerpresence.PresenceChange{}
err := json.Unmarshal([]byte(presenceChangeStr), p)
if err != nil {
return fmt.Errorf("unmarshal presence change: %w", err)
}

bytes, err := database.EncodePresenceChange(p)
if err != nil {
return fmt.Errorf("encode error: %w", err)
}
operation = mongo.NewUpdateOneModel().SetFilter(bson.M{
"_id": doc["_id"],
}).SetUpdate(bson.M{
"$set": bson.M{
"presence_change": []byte(presenceChangeStr),
"presence_change": bytes,
},
})
}
Expand Down

0 comments on commit 083ab63

Please sign in to comment.