Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: fix batch update database query when database is empty (#5927)

Danny Xu7fbb3e460d59
diff --git a/backend/store/database.go b/backend/store/database.go
index cc961a7cc6..2f922e633a 100644
--- a/backend/store/database.go
+++ b/backend/store/database.go
@@ -523,11 +523,15 @@ func (s *Store) BatchUpdateDatabaseProject(ctx context.Context, databases []*Dat
wheres = append(wheres, fmt.Sprintf("(environment.resource_id = $%d AND instance.resource_id = $%d AND db.name = $%d)", 3*i+3, 3*i+4, 3*i+5))
args = append(args, database.EnvironmentID, database.InstanceID, database.DatabaseName)
}
+ databaseClause := ""
+ if len(wheres) > 0 {
+ databaseClause = fmt.Sprintf(" AND (%s)", strings.Join(wheres, " OR "))
+ }
if _, err := tx.ExecContext(ctx, fmt.Sprintf(`
UPDATE db
SET project_id = $1, updater_id = $2
FROM instance JOIN environment ON instance.environment_id = environment.id
- WHERE db.instance_id = instance.id AND (%s);`, strings.Join(wheres, " OR ")),
+ WHERE db.instance_id = instance.id %s;`, databaseClause),
args...,
); err != nil {
return nil, err