Skip to content

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

chore: don't require database field for spanner instance (#4325)

p0ny9fc3e0100f8a
diff --git a/frontend/src/components/CreateInstanceForm.vue b/frontend/src/components/CreateInstanceForm.vue
index 53db0262dd..861634ec1e 100644
--- a/frontend/src/components/CreateInstanceForm.vue
+++ b/frontend/src/components/CreateInstanceForm.vue
@@ -248,12 +248,6 @@
<div class="flex flex-row items-center space-x-2">
<label for="database" class="textlabel block">
{{ $t("common.database") }}
- <template v-if="state.instance.engine === 'SPANNER'">
- <span style="color: red">*</span>
- <p class="text-sm text-gray-500 mt-1">
- {{ $t("instance.used-for-testing-connection") }}
- </p>
- </template>
</label>
</div>
<input
@@ -459,10 +453,7 @@ const embeddedPostgresInstance = ref<Partial<InstanceCreate>>();
const allowCreate = computed(() => {
if (state.instance.engine === "SPANNER") {
return (
- state.instance.name &&
- state.instance.host &&
- state.instance.password &&
- state.instance.database
+ state.instance.name && state.instance.host && state.instance.password
);
}
return state.instance.name && state.instance.host;
@@ -497,9 +488,7 @@ const showSSL = computed((): boolean => {
});
const showDatabase = computed((): boolean => {
- return (
- state.instance.engine === "POSTGRES" || state.instance.engine === "SPANNER"
- );
+ return state.instance.engine === "POSTGRES";
});
const showAuthenticationDatabase = computed((): boolean => {
@@ -692,11 +681,6 @@ const tryCreate = () => {
if (instance.engine === "MONGODB") {
connectionInfo.database = instance.database;
}
- // Spanner must connect to a specific database.
- // To test connection, we must set database.
- if (instance.engine === "SPANNER") {
- connectionInfo.database = instance.database;
- }
state.isPingingInstance = true;
sqlStore
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 9903508284..e8376cb7c0 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -51,10 +51,16 @@
<template v-else-if="state.instance.engine === 'SPANNER'">
{{ $t("instance.project-id-and-instance-id") }}
<span style="color: red">*</span>
- <p class="text-sm text-gray-500 mt-1 mb-2">
- Don't know where to find project ID and instance ID? Check this
- link!
- <!-- TODO(p0ny): fix the link -->
+ <p class="text-sm text-gray-500 mt-1">
+ {{ $t("instance.find-gcp-project-id-and-instance-id") }}
+ <a
+ href="https://www.bytebase.com/docs/how-to/spanner/how-to-find-project-id-and-instance-id"
+ target="_blank"
+ class="normal-link inline-flex items-center"
+ >
+ {{ $t("common.detailed-guide")
+ }}<heroicons-outline:external-link class="w-4 h-4 ml-1"
+ /></a>
</p>
</template>
<template v-else>
@@ -239,11 +245,22 @@
<label for="password" class="textlabel block">
<template v-if="state.instance.engine === 'SPANNER'">
{{ $t("common.credentials") }}
+ <span class="text-red-600">*</span>
+ <p class="text-sm text-gray-500 mt-1">
+ {{ $t("instance.create-gcp-credentials") }}
+ <a
+ href="https://www.bytebase.com/docs/how-to/spanner/how-to-create-a-service-account-for-bytebase"
+ target="_blank"
+ class="normal-link inline-flex items-center"
+ >{{ $t("common.detailed-guide") }}
+ <heroicons-outline:external-link class="w-4 h-4 ml-1"
+ /></a>
+ </p>
</template>
<template v-else>
{{ $t("common.password") }}
+ <span class="text-red-600">*</span>
</template>
- <span class="text-red-600">*</span>
</label>
<BBCheckbox
:title="$t('common.empty')"
diff --git a/plugin/db/spanner/spanner.go b/plugin/db/spanner/spanner.go
index 61ceba3c74..8b1d66fc3d 100644
--- a/plugin/db/spanner/spanner.go
+++ b/plugin/db/spanner/spanner.go
@@ -11,7 +11,7 @@ import (
spanner "cloud.google.com/go/spanner"
spannerdb "cloud.google.com/go/spanner/admin/database/apiv1"
- adminpb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
+ "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"go.uber.org/zap"
sppb "cloud.google.com/go/spanner/apiv1/spannerpb"
@@ -125,24 +125,17 @@ func (d *Driver) Close(_ context.Context) error {
return d.dbClient.Close()
}
-// Ping pings the database.
+// Ping pings the instance.
func (d *Driver) Ping(ctx context.Context) error {
- iter := d.client.Single().Query(ctx, spanner.NewStatement("SELECT 1"))
- defer iter.Stop()
-
- var i int64
- row, err := iter.Next()
- if err != nil {
- return err
- }
- if err := row.Column(0, &i); err != nil {
- return err
- }
- if i != 1 {
- return errors.New("expect to get 1")
+ iter := d.dbClient.ListDatabases(ctx, &databasepb.ListDatabasesRequest{
+ Parent: d.config.Host,
+ })
+ _, err := iter.Next()
+ if err == iterator.Done {
+ return nil
}
- if _, err = iter.Next(); err != iterator.Done {
- return errors.New("expect no more rows")
+ if err != nil {
+ return errors.Wrap(err, "spanner: bad connection")
}
return nil
}
@@ -178,7 +171,7 @@ func (d *Driver) Execute(ctx context.Context, statement string, createDatabase b
}()
if ddl {
- op, err := d.dbClient.UpdateDatabaseDdl(ctx, &adminpb.UpdateDatabaseDdlRequest{
+ op, err := d.dbClient.UpdateDatabaseDdl(ctx, &databasepb.UpdateDatabaseDdlRequest{
Database: getDSN(d.config.Host, d.dbName),
Statements: stmts,
})
@@ -261,7 +254,7 @@ func (d *Driver) Query(ctx context.Context, statement string, queryContext *db.Q
func (d *Driver) queryAdmin(ctx context.Context, statement string) ([]interface{}, error) {
if isDDL(statement) {
- op, err := d.dbClient.UpdateDatabaseDdl(ctx, &adminpb.UpdateDatabaseDdlRequest{
+ op, err := d.dbClient.UpdateDatabaseDdl(ctx, &databasepb.UpdateDatabaseDdlRequest{
Database: getDSN(d.config.Host, d.dbName),
Statements: []string{statement},
})