Skip to content

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

fix: batch update db query (#7384)

Danny Xubb98bce742a5
diff --git a/backend/store/database.go b/backend/store/database.go
index c54ad9628a..46ab0f33e7 100644
--- a/backend/store/database.go
+++ b/backend/store/database.go
@@ -529,7 +529,7 @@ func (s *Store) BatchUpdateDatabaseProject(ctx context.Context, databases []*Dat
var wheres []string
args := []any{project.UID, updaterID}
for i, database := range databases {
- wheres = append(wheres, fmt.Sprintf("(instance.resource_id = $%d AND db.name = $%d)", 2*i+2, 2*i+3))
+ wheres = append(wheres, fmt.Sprintf("(instance.resource_id = $%d AND db.name = $%d)", 2*i+3, 2*i+4))
args = append(args, database.InstanceID, database.DatabaseName)
}
databaseClause := ""
@@ -539,7 +539,7 @@ func (s *Store) BatchUpdateDatabaseProject(ctx context.Context, databases []*Dat
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
+ FROM instance
WHERE db.instance_id = instance.id %s;`, databaseClause),
args...,
); err != nil {