mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-18 04:29:54 +00:00
fis association replace
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user