fis association replace

This commit is contained in:
Pascal Fischer
2025-07-03 13:35:18 +02:00
parent 7132642e4c
commit e78b7dd058
3 changed files with 9 additions and 9 deletions

View File

@@ -39,6 +39,11 @@ func MigrateFieldFromGobToJSON[T any, S any](ctx context.Context, db *gorm.DB, f
return nil
}
if !db.Migrator().HasColumn(&model, fieldName) {
log.WithContext(ctx).Debugf("Table for %T does not have column %s, no migration needed", model, fieldName)
return nil
}
stmt := &gorm.Statement{DB: db}
err := stmt.Parse(model)
if err != nil {

View File

@@ -1810,17 +1810,12 @@ func (s *SqlStore) SaveGroup(ctx context.Context, lockStrength LockingStrength,
group.StoreGroupPeers()
tx := s.db
if lockStrength != LockingStrengthNone {
tx = tx.Clauses(clause.Locking{Strength: string(lockStrength)})
}
if err := tx.Model(group).Association("Peers").Replace(group.Peers); err != nil {
if err := s.db.Model(group).Association("GroupPeers").Replace(group.GroupPeers); err != nil {
log.WithContext(ctx).Errorf("failed to replace peers for group %s: %v", group.ID, err)
return status.Errorf(status.Internal, "failed to sync group peers")
}
if err := tx.Save(group).Error; err != nil {
if err := s.db.Save(group).Error; err != nil {
log.WithContext(ctx).Errorf("failed to save group to store: %v", err)
return status.Errorf(status.Internal, "failed to save group to store")
}

View File

@@ -45,7 +45,7 @@ func (g *Group) LoadGroupPeers() {
for i, peer := range g.GroupPeers {
g.Peers[i] = peer.PeerID
}
// g.GroupPeers = nil
g.GroupPeers = nil
}
func (g *Group) StoreGroupPeers() {
g.GroupPeers = make([]GroupPeer, len(g.Peers))
@@ -55,7 +55,7 @@ func (g *Group) StoreGroupPeers() {
PeerID: peer,
}
}
// g.Peers = nil
g.Peers = nil
}
// EventMeta returns activity event meta related to the group