Skip to content

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

chore: no magic grant (#15413)

Danny Xu0b3bc1212b21
diff --git a/backend/api/v1/rollout_service_task.go b/backend/api/v1/rollout_service_task.go
index 1f5badd355..1100c59693 100644
--- a/backend/api/v1/rollout_service_task.go
+++ b/backend/api/v1/rollout_service_task.go
@@ -606,25 +606,18 @@ func getCreateDatabaseStatement(dbType storepb.Engine, c *storepb.PlanConfig_Cre
return fmt.Sprintf("CREATE DATABASE `%s` CHARACTER SET %s COLLATE %s;", databaseName, c.CharacterSet, c.Collation), nil
case storepb.Engine_MSSQL:
return fmt.Sprintf(`CREATE DATABASE "%s";`, databaseName), nil
- case storepb.Engine_POSTGRES:
- // On Cloud RDS, the data source role isn't the actual superuser with sudo privilege.
- // We need to grant the database owner role to the data source admin so that Bytebase can have permission for the database using the data source admin.
- if adminDatasourceUser != "" && c.Owner != adminDatasourceUser {
- stmt = fmt.Sprintf("GRANT \"%s\" TO \"%s\";\n", c.Owner, adminDatasourceUser)
- }
- if c.Collation == "" {
- stmt = fmt.Sprintf("%sCREATE DATABASE \"%s\" ENCODING %q;", stmt, databaseName, c.CharacterSet)
- } else {
- stmt = fmt.Sprintf("%sCREATE DATABASE \"%s\" ENCODING %q LC_COLLATE %q;", stmt, databaseName, c.CharacterSet, c.Collation)
+ case storepb.Engine_POSTGRES, storepb.Engine_COCKROACHDB:
+ collationPart := ""
+ if c.Collation != "" {
+ collationPart = fmt.Sprintf(" LC_COLLATE %q", c.Collation)
}
+ stmt = fmt.Sprintf("%sCREATE DATABASE \"%s\" ENCODING %q%s;", stmt, databaseName, c.CharacterSet, collationPart)
// Set the database owner.
// We didn't use CREATE DATABASE WITH OWNER because RDS requires the current role to be a member of the database owner.
// However, people can still use ALTER DATABASE to change the owner afterwards.
// Error string below:
// query: CREATE DATABASE h1 WITH OWNER hello;
// ERROR: must be member of role "hello"
- //
- // TODO(d): alter schema "public" owner to the database owner.
return fmt.Sprintf("%s\nALTER DATABASE \"%s\" OWNER TO \"%s\";", stmt, databaseName, c.Owner), nil
case storepb.Engine_CLICKHOUSE:
clusterPart := ""
@@ -660,26 +653,6 @@ func getCreateDatabaseStatement(dbType storepb.Engine, c *storepb.PlanConfig_Cre
stmt = fmt.Sprintf("%s WITH\n\t%s", stmt, strings.Join(list, "\n\t"))
}
return fmt.Sprintf("%s;", stmt), nil
- case storepb.Engine_COCKROACHDB:
- // On Cloud RDS, the data source role isn't the actual superuser with sudo privilege.
- // We need to grant the database owner role to the data source admin so that Bytebase can have permission for the database using the data source admin.
- if adminDatasourceUser != "" && c.Owner != adminDatasourceUser {
- stmt = fmt.Sprintf("GRANT \"%s\" TO \"%s\";\n", c.Owner, adminDatasourceUser)
- }
- if c.Collation == "" {
- stmt = fmt.Sprintf("%sCREATE DATABASE \"%s\" ENCODING %q;", stmt, databaseName, c.CharacterSet)
- } else {
- stmt = fmt.Sprintf("%sCREATE DATABASE \"%s\" ENCODING %q LC_COLLATE %q;", stmt, databaseName, c.CharacterSet, c.Collation)
- }
- // Set the database owner.
- // We didn't use CREATE DATABASE WITH OWNER because RDS requires the current role to be a member of the database owner.
- // However, people can still use ALTER DATABASE to change the owner afterwards.
- // Error string below:
- // query: CREATE DATABASE h1 WITH OWNER hello;
- // ERROR: must be member of role "hello"
- //
- // TODO(d): alter schema "public" owner to the database owner.
- return fmt.Sprintf("%s\nALTER DATABASE \"%s\" OWNER TO \"%s\";", stmt, databaseName, c.Owner), nil
case storepb.Engine_HIVE:
return fmt.Sprintf("CREATE DATABASE %s;", databaseName), nil
}