Skip to content

Commit

Permalink
Update presence_change DB migration for proto marshaling (#1075)
Browse files Browse the repository at this point in the history
This migration script transforms existing presence_change data from JSON to
Protobuf format, aligning with recent encoding changes in the main codebase.
  • Loading branch information
chacha912 authored Nov 21, 2024
1 parent bd886c5 commit b03f82e
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 b03f82e

Please sign in to comment.