Skip to content

Commit

Permalink
fix: batch update db query (#7385)
Browse files Browse the repository at this point in the history
(cherry picked from commit fecacd3)

Co-authored-by: d-bytebase <d@bytebase.com>
  • Loading branch information
github-actions[bot] and d-bytebase committed Aug 3, 2023
1 parent d9fa70a commit 9ec4b0e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/store/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand All @@ -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 {
Expand Down

0 comments on commit 9ec4b0e

Please sign in to comment.