Skip to content

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

chore: tenant new db use the same engine type (#8082)

Danny Xu52bc7e8b42ab
diff --git a/backend/runner/taskrun/database_create_executor.go b/backend/runner/taskrun/database_create_executor.go
index 35a0b6e5d1..42479a1375 100644
--- a/backend/runner/taskrun/database_create_executor.go
+++ b/backend/runner/taskrun/database_create_executor.go
@@ -323,6 +323,7 @@ func getConnectionStatement(dbType db.Type, databaseName string) (string, error)
func (*DatabaseCreateExecutor) getSchemaFromPeerTenantDatabase(ctx context.Context, stores *store.Store, dbFactory *dbfactory.DBFactory, instance *store.InstanceMessage, project *store.ProjectMessage, database *store.DatabaseMessage) (string, string, error) {
allDatabases, err := stores.ListDatabases(ctx, &store.FindDatabaseMessage{
ProjectID: &project.ResourceID,
+ Engine: &instance.Engine,
})
if err != nil {
return "", "", errors.Wrapf(err, "Failed to fetch databases in project ID: %v", project.UID)
diff --git a/backend/store/database.go b/backend/store/database.go
index 4b1eada5ba..7aa95d8147 100644
--- a/backend/store/database.go
+++ b/backend/store/database.go
@@ -12,6 +12,7 @@ import (
"github.com/bytebase/bytebase/backend/common"
api "github.com/bytebase/bytebase/backend/legacyapi"
+ "github.com/bytebase/bytebase/backend/plugin/db"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
@@ -163,6 +164,7 @@ type FindDatabaseMessage struct {
InstanceID *string
DatabaseName *string
UID *int
+ Engine *db.Type
// When this is used, we will return databases from archived instances or environments.
// This is used for existing tasks with archived databases.
ShowDeleted bool
@@ -607,6 +609,9 @@ func (*Store) listDatabaseImplV2(ctx context.Context, tx *Tx, find *FindDatabase
if v := find.UID; v != nil {
where, args = append(where, fmt.Sprintf("db.id = $%d", len(args)+1)), append(args, *v)
}
+ if v := find.Engine; v != nil {
+ where, args = append(where, fmt.Sprintf("instance.engine = $%d", len(args)+1)), append(args, *v)
+ }
if !find.ShowDeleted {
where, args = append(where, fmt.Sprintf("COALESCE((SELECT environment.row_status AS instance_environment_status FROM environment JOIN instance ON environment.id = instance.environment_id WHERE instance.id = db.instance_id), $%d) = $%d", len(args)+1, len(args)+2)), append(args, api.Normal, api.Normal)
where, args = append(where, fmt.Sprintf("COALESCE((SELECT environment.row_status AS db_environment_status FROM environment WHERE environment.id = db.environment_id), $%d) = $%d", len(args)+1, len(args)+2)), append(args, api.Normal, api.Normal)