removed condition on 1 yop per account

This commit is contained in:
crn4
2026-04-21 15:12:52 +02:00
parent e62521132c
commit 8fe2b5ec1e
5 changed files with 12 additions and 49 deletions

View File

@@ -17,7 +17,6 @@ import (
"time"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/rs/xid"
log "github.com/sirupsen/logrus"
@@ -5476,26 +5475,11 @@ func (s *SqlStore) SaveProxy(ctx context.Context, p *proxy.Proxy) error {
result := s.db.WithContext(ctx).Save(p)
if result.Error != nil {
log.WithContext(ctx).Errorf("failed to save proxy: %v", result.Error)
if isUniqueConstraintError(result.Error) {
return proxy.ErrAccountProxyAlreadyExists
}
return status.Errorf(status.Internal, "failed to save proxy")
}
return nil
}
func isUniqueConstraintError(err error) bool {
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) && pgErr.Code == "23505" {
return true
}
errStr := err.Error()
return strings.Contains(errStr, "UNIQUE constraint") ||
strings.Contains(errStr, "duplicate key") ||
strings.Contains(errStr, "Duplicate entry") ||
strings.Contains(errStr, "Error 1062")
}
func (s *SqlStore) DisconnectProxy(ctx context.Context, proxyID string) error {
now := time.Now()
result := s.db.WithContext(ctx).

View File

@@ -502,6 +502,9 @@ func getMigrationsPostAuto(ctx context.Context) []migrationFunc {
func(db *gorm.DB) error {
return migration.CreateIndexIfNotExists[nbpeer.Peer](ctx, db, "idx_peers_key_unique", "key")
},
func(db *gorm.DB) error {
return migration.DropIndex[proxy.Proxy](ctx, db, "idx_proxy_account_id_unique")
},
}
}