Skip to content

Commit

Permalink
Readd deleted database / table wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Junos committed Jun 6, 2022
1 parent 40ab5fc commit 6aa86ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mysql/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ func CreateGrant(d *schema.ResourceData, meta interface{}) error {
}
}

// DB and table have to be wrappedsin backticks in some cases.
databaseWrapped := formatDatabaseName(database)
tableWrapped := formatTableName(table)
if (!isRole || hasPrivs) && rolesGranted == 0 {
grantOn = fmt.Sprintf(" ON %s.%s", database, table)
grantOn = fmt.Sprintf(" ON %s.%s", databaseWrapped, tableWrapped)
}

stmtSQL := fmt.Sprintf("GRANT %s%s TO %s",
Expand All @@ -242,9 +245,9 @@ func CreateGrant(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error running SQL (%s): %s", stmtSQL, err)
}

id := fmt.Sprintf("%s@%s:%s", user, host, database)
id := fmt.Sprintf("%s@%s:%s", user, host, databaseWrapped)
if isRole {
id = fmt.Sprintf("%s:%s", role, database)
id = fmt.Sprintf("%s:%s", role, databaseWrapped)
}

d.SetId(id)
Expand Down

0 comments on commit 6aa86ab

Please sign in to comment.