Skip to content

Commit

Permalink
Escape Groups table name for newer MySQL versions (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
siggisim authored Oct 15, 2021
1 parent 0d50823 commit 95eff13
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion enterprise/server/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func lookupUserFromSubID(env environment.Env, ctx context.Context, subID string)
g.use_group_owned_executors,
g.saml_idp_metadata_url,
ug.role
FROM Groups AS g, UserGroups AS ug
FROM `+"`Groups`"+` AS g, UserGroups AS ug
WHERE g.group_id = ug.group_group_id
AND ug.membership_status = ?
AND ug.user_user_id = ?
Expand Down
2 changes: 1 addition & 1 deletion enterprise/server/backends/userdb/userdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (d *UserDB) InsertOrUpdateGroup(ctx context.Context, g *tables.Group) (stri

groupID = g.GroupID
res := tx.Exec(`
UPDATE Groups SET name = ?, url_identifier = ?, owned_domain = ?, sharing_enabled = ?,
UPDATE `+"`Groups`"+` SET name = ?, url_identifier = ?, owned_domain = ?, sharing_enabled = ?,
use_group_owned_executors = ?
WHERE group_id = ?`,
g.Name, g.URLIdentifier, g.OwnedDomain, g.SharingEnabled, g.UseGroupOwnedExecutors,
Expand Down
2 changes: 1 addition & 1 deletion server/backends/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (c *GithubClient) Link(w http.ResponseWriter, r *http.Request) {
}

err = dbHandle.Exec(
"UPDATE Groups SET github_token = ? WHERE group_id = ?",
`UPDATE `+"`Groups`"+` SET github_token = ? WHERE group_id = ?`,
accessTokenResponse.AccessToken, groupID).Error
if err != nil {
redirectWithError(w, r, status.PermissionDeniedErrorf("Error linking github account to user: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion server/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func PreAutoMigrate(db *gorm.DB) ([]PostAutoMigrateLogic, error) {
}
// Before creating a unique index, need to replace empty strings with NULL.
if !m.HasIndex("Groups", "url_identifier_unique_index") {
if err := db.Exec(`UPDATE Groups SET url_identifier = NULL WHERE url_identifier = ""`).Error; err != nil {
if err := db.Exec(`UPDATE ` + "`Groups`" + ` SET url_identifier = NULL WHERE url_identifier = ""`).Error; err != nil {
return nil, err
}
}
Expand Down

0 comments on commit 95eff13

Please sign in to comment.