Skip to content

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

chore: bq fe (#12089)

Danny Xu46bbe5dd7a75
diff --git a/backend/api/v1/common.go b/backend/api/v1/common.go
index d4500bf584..7255f58fd3 100644
--- a/backend/api/v1/common.go
+++ b/backend/api/v1/common.go
@@ -349,6 +349,8 @@ func convertToEngine(engine storepb.Engine) v1pb.Engine {
return v1pb.Engine_HIVE
case storepb.Engine_ELASTICSEARCH:
return v1pb.Engine_ELASTICSEARCH
+ case storepb.Engine_BIGQUERY:
+ return v1pb.Engine_BIGQUERY
}
return v1pb.Engine_ENGINE_UNSPECIFIED
}
@@ -397,6 +399,8 @@ func convertEngine(engine v1pb.Engine) storepb.Engine {
return storepb.Engine_HIVE
case v1pb.Engine_ELASTICSEARCH:
return storepb.Engine_ELASTICSEARCH
+ case v1pb.Engine_BIGQUERY:
+ return storepb.Engine_BIGQUERY
}
return storepb.Engine_ENGINE_UNSPECIFIED
}
diff --git a/backend/plugin/db/bigquery/bigquery.go b/backend/plugin/db/bigquery/bigquery.go
new file mode 100644
index 0000000000..a4a2f13b2f
--- /dev/null
+++ b/backend/plugin/db/bigquery/bigquery.go
@@ -0,0 +1,73 @@
+// Package spanner is the plugin for BigQuery driver.
+package bigquery
+
+import (
+ "context"
+ "database/sql"
+
+ "github.com/bytebase/bytebase/backend/plugin/db"
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
+ v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
+)
+
+var (
+ _ db.Driver = (*Driver)(nil)
+)
+
+func init() {
+ db.Register(storepb.Engine_BIGQUERY, newDriver)
+}
+
+// Driver is the Spanner driver.
+type Driver struct {
+ // config db.ConnectionConfig
+ // connCtx db.ConnectionContext
+
+ // databaseName is the currently connected database name.
+ // databaseName string
+}
+
+func newDriver(_ db.DriverConfig) db.Driver {
+ return &Driver{}
+}
+
+// Open opens a Spanner driver. It must connect to a specific database.
+// If database isn't provided, part of the driver cannot function.
+func (*Driver) Open(_ context.Context, _ storepb.Engine, _ db.ConnectionConfig) (db.Driver, error) {
+ return nil, nil
+}
+
+// Close closes the driver.
+func (*Driver) Close(_ context.Context) error {
+ return nil
+}
+
+// Ping pings the instance.
+func (*Driver) Ping(_ context.Context) error {
+ return nil
+}
+
+// GetType returns the database type.
+func (*Driver) GetType() storepb.Engine {
+ return storepb.Engine_BIGQUERY
+}
+
+// GetDB gets the database.
+func (*Driver) GetDB() *sql.DB {
+ return nil
+}
+
+// Execute executes a SQL statement.
+func (*Driver) Execute(_ context.Context, _ string, _ db.ExecuteOptions) (int64, error) {
+ return 0, nil
+}
+
+// QueryConn queries a SQL statement in a given connection.
+func (*Driver) QueryConn(_ context.Context, _ *sql.Conn, _ string, _ *db.QueryContext) ([]*v1pb.QueryResult, error) {
+ return nil, nil
+}
+
+// RunStatement executes a SQL statement.
+func (*Driver) RunStatement(_ context.Context, _ *sql.Conn, _ string) ([]*v1pb.QueryResult, error) {
+ return nil, nil
+}
diff --git a/backend/plugin/db/bigquery/dump.go b/backend/plugin/db/bigquery/dump.go
new file mode 100644
index 0000000000..08f3a18096
--- /dev/null
+++ b/backend/plugin/db/bigquery/dump.go
@@ -0,0 +1,11 @@
+package bigquery
+
+import (
+ "context"
+ "io"
+)
+
+// Dump dumps the database.
+func (*Driver) Dump(_ context.Context, _ io.Writer, _ bool) (string, error) {
+ return "", nil
+}
diff --git a/backend/plugin/db/bigquery/role.go b/backend/plugin/db/bigquery/role.go
new file mode 100644
index 0000000000..272660b079
--- /dev/null
+++ b/backend/plugin/db/bigquery/role.go
@@ -0,0 +1,34 @@
+package bigquery
+
+import (
+ "context"
+
+ "github.com/pkg/errors"
+
+ "github.com/bytebase/bytebase/backend/plugin/db"
+)
+
+// CreateRole creates the role.
+func (*Driver) CreateRole(_ context.Context, _ *db.DatabaseRoleUpsertMessage) (*db.DatabaseRoleMessage, error) {
+ return nil, errors.Errorf("create role for spanner is not implemented yet")
+}
+
+// UpdateRole updates the role.
+func (*Driver) UpdateRole(_ context.Context, _ string, _ *db.DatabaseRoleUpsertMessage) (*db.DatabaseRoleMessage, error) {
+ return nil, errors.Errorf("update role for spanner is not implemented yet")
+}
+
+// FindRole finds the role by name.
+func (*Driver) FindRole(_ context.Context, _ string) (*db.DatabaseRoleMessage, error) {
+ return nil, errors.Errorf("find role for spanner is not implemented yet")
+}
+
+// ListRole lists the role.
+func (*Driver) ListRole(_ context.Context) ([]*db.DatabaseRoleMessage, error) {
+ return nil, errors.Errorf("list role for spanner is not implemented yet")
+}
+
+// DeleteRole deletes the role by name.
+func (*Driver) DeleteRole(_ context.Context, _ string) error {
+ return errors.Errorf("delete role for spanner is not implemented yet")
+}
diff --git a/backend/plugin/db/bigquery/sync.go b/backend/plugin/db/bigquery/sync.go
new file mode 100644
index 0000000000..b7c52a77b9
--- /dev/null
+++ b/backend/plugin/db/bigquery/sync.go
@@ -0,0 +1,31 @@
+package bigquery
+
+import (
+ "context"
+ "time"
+
+ "github.com/pkg/errors"
+
+ "github.com/bytebase/bytebase/backend/plugin/db"
+ storepb "github.com/bytebase/bytebase/proto/generated-go/store"
+)
+
+// SyncInstance syncs the instance.
+func (*Driver) SyncInstance(_ context.Context) (*db.InstanceMetadata, error) {
+ return nil, nil
+}
+
+// SyncDBSchema syncs a single database schema.
+func (*Driver) SyncDBSchema(_ context.Context) (*storepb.DatabaseSchemaMetadata, error) {
+ return nil, nil
+}
+
+// SyncSlowQuery syncs the slow query.
+func (*Driver) SyncSlowQuery(_ context.Context, _ time.Time) (map[string]*storepb.SlowQueryStatistics, error) {
+ return nil, errors.Errorf("not implemented")
+}
+
+// CheckSlowQueryLogEnabled checks if slow query log is enabled.
+func (*Driver) CheckSlowQueryLogEnabled(_ context.Context) error {
+ return errors.Errorf("not implemented")
+}
diff --git a/backend/server/ultimate.go b/backend/server/ultimate.go
index 4f33bbe653..83158541dd 100644
--- a/backend/server/ultimate.go
+++ b/backend/server/ultimate.go
@@ -4,6 +4,7 @@ package server
import (
// Drivers.
+ _ "github.com/bytebase/bytebase/backend/plugin/db/bigquery"
_ "github.com/bytebase/bytebase/backend/plugin/db/clickhouse"
_ "github.com/bytebase/bytebase/backend/plugin/db/dm"
_ "github.com/bytebase/bytebase/backend/plugin/db/elasticsearch"
diff --git a/frontend/src/assets/bigquery.svg b/frontend/src/assets/bigquery.svg
new file mode 100644
index 0000000000..c6b3ceaca5
--- /dev/null
+++ b/frontend/src/assets/bigquery.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" viewBox="0 0 24 24"><defs><style>.cls-1{fill:#aecbfa;}.cls-1,.cls-2,.cls-3{fill-rule:evenodd;}.cls-2{fill:#669df6;}.cls-3{fill:#4285f4;}</style></defs><title>Icon_24px_BigQuery_Color</title><g data-name="Product Icons"><g ><path class="cls-1" d="M6.73,10.83v2.63A4.91,4.91,0,0,0,8.44,15.2V10.83Z"/><path class="cls-2" d="M9.89,8.41v7.53A7.62,7.62,0,0,0,11,16,8,8,0,0,0,12,16V8.41Z"/><path class="cls-1" d="M13.64,11.86v3.29a5,5,0,0,0,1.7-1.82V11.86Z"/><path class="cls-3" d="M17.74,16.32l-1.42,1.42a.42.42,0,0,0,0,.6l3.54,3.54a.42.42,0,0,0,.59,0l1.43-1.43a.42.42,0,0,0,0-.59l-3.54-3.54a.42.42,0,0,0-.6,0"/><path class="cls-2" d="M11,2a9,9,0,1,0,9,9,9,9,0,0,0-9-9m0,15.69A6.68,6.68,0,1,1,17.69,11,6.68,6.68,0,0,1,11,17.69"/></g></g></svg>
\ No newline at end of file
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/CreateDataSourceExample.vue b/frontend/src/components/InstanceForm/DataSourceSection/CreateDataSourceExample.vue
index 25f081e15e..30fab5658a 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/CreateDataSourceExample.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/CreateDataSourceExample.vue
@@ -425,6 +425,8 @@ db.createUser({
`;
case Engine.SPANNER:
return "";
+ case Engine.BIGQUERY:
+ return "";
case Engine.REDIS:
return `ACL SETUSER ${DATASOURCE_ADMIN_USER_NAME} on >YOUR_DB_PWD +@all &*`;
case Engine.MSSQL:
@@ -583,6 +585,8 @@ db.createUser({
`;
case Engine.SPANNER:
return "";
+ case Engine.BIGQUERY:
+ return "";
case Engine.REDIS:
return `ACL SETUSER ${DATASOURCE_READONLY_USER_NAME} on >YOUR_DB_PWD +@read &*`;
}
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
index 7f8602c7bf..e8e7541666 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
@@ -1,6 +1,6 @@
<template>
<!-- eslint-disable vue/no-mutating-props -->
- <template v-if="basicInfo.engine !== Engine.SPANNER">
+ <template v-if="basicInfo.engine !== Engine.SPANNER && basicInfo.engine !== Engine.BIGQUERY ">
<div
v-if="
basicInfo.engine === Engine.MYSQL ||
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceSection.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceSection.vue
index 058999e976..20ef66b744 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceSection.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceSection.vue
@@ -44,7 +44,7 @@ const handleCreateRODataSource = () => {
database: adminDataSource.value.database,
username: DATASOURCE_READONLY_USER_NAME,
};
- if (basicInfo.value.engine === Engine.SPANNER) {
+ if (basicInfo.value.engine === Engine.SPANNER || basicInfo.value.engine === Engine.BIGQUERY) {
ds.host = adminDataSource.value.host;
}
dataSourceEditState.value.dataSources.push(ds);
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vue
index b4b9092815..d4d77e098a 100644
--- a/frontend/src/components/InstanceForm/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm/InstanceForm.vue
@@ -106,7 +106,7 @@
</div>
<div class="sm:col-span-3 sm:col-start-1">
- <template v-if="basicInfo.engine !== Engine.SPANNER">
+ <template v-if="basicInfo.engine !== Engine.SPANNER && basicInfo.engine !== Engine.BIGQUERY">
<label for="host" class="textlabel block">
<template v-if="basicInfo.engine === Engine.SNOWFLAKE">
{{ $t("instance.account-locator") }}
@@ -166,7 +166,7 @@
<template
v-if="
- basicInfo.engine !== Engine.SPANNER &&
+ (basicInfo.engine !== Engine.SPANNER && basicInfo.engine !== Engine.BIGQUERY) &&
adminDataSource.authenticationType !==
DataSource_AuthenticationType.GOOGLE_CLOUD_SQL_IAM
"
@@ -764,7 +764,7 @@ const handleSelectEnvironmentUID = (uid: string | undefined) => {
// the host name between 127.0.0.1/host.docker.internal and "" if user hasn't changed default yet.
const changeInstanceEngine = (engine: Engine) => {
context.resetDataSource();
- if (engine === Engine.SNOWFLAKE || engine === Engine.SPANNER) {
+ if (engine === Engine.SNOWFLAKE || engine === Engine.SPANNER || engine === Engine.BIGQUERY) {
if (
adminDataSource.value.host === "127.0.0.1" ||
adminDataSource.value.host === "host.docker.internal"
diff --git a/frontend/src/components/InstanceForm/constants.ts b/frontend/src/components/InstanceForm/constants.ts
index 056e3eb282..7e34a4de6a 100644
--- a/frontend/src/components/InstanceForm/constants.ts
+++ b/frontend/src/components/InstanceForm/constants.ts
@@ -77,6 +77,7 @@ export const EngineIconPath: Record<string, string> = {
"@/assets/db-elasticsearch.svg",
import.meta.url
).href,
+ [Engine.BIGQUERY]: new URL("@/assets/bigquery.svg", import.meta.url).href,
};
export const MongoDBConnectionStringSchemaList = [
diff --git a/frontend/src/types/instance.ts b/frontend/src/types/instance.ts
index cecd0f4eb0..205bfcead1 100644
--- a/frontend/src/types/instance.ts
+++ b/frontend/src/types/instance.ts
@@ -20,6 +20,7 @@ export const EngineTypeList = [
"OCEANBASE",
"DM",
"RISINGWAVE",
+ "BIGQUERY",
] as const;
export type EngineType = (typeof EngineTypeList)[number];
@@ -56,7 +57,9 @@ export function convertEngineType(type: EngineType): Engine {
return Engine.DM;
case "RISINGWAVE":
return Engine.RISINGWAVE;
- }
+ case "BIGQUERY":
+ return Engine.BIGQUERY;
+ }
return Engine.ENGINE_UNSPECIFIED;
}
@@ -96,6 +99,8 @@ export function defaultCharset(type: EngineType): string {
return "UNICODE";
case "RISINGWAVE":
return "UTF8";
+ case "BIGQUERY":
+ return "";
}
}
@@ -131,7 +136,9 @@ export function engineName(type: EngineType): string {
return "DM";
case "RISINGWAVE":
return "RisingWave";
- }
+ case "BIGQUERY":
+ return "BigQuery";
+ }
}
export function defaultCollation(type: EngineType): string {
@@ -164,6 +171,8 @@ export function defaultCollation(type: EngineType): string {
return "";
case "DM":
return "BINARY_CI";
+ case "BIGQUERY":
+ return "";
}
}
diff --git a/frontend/src/types/v1/instance.ts b/frontend/src/types/v1/instance.ts
index 7301aa3e3e..f7db58d3f8 100644
--- a/frontend/src/types/v1/instance.ts
+++ b/frontend/src/types/v1/instance.ts
@@ -71,6 +71,8 @@ export const defaultCharsetOfEngineV1 = (engine: Engine): string => {
return "UTF8";
case Engine.HIVE:
return "default";
+ case Engine.BIGQUERY:
+ return ""
}
return "";
};
@@ -107,6 +109,8 @@ export const defaultCollationOfEngineV1 = (engine: Engine): string => {
return "BINARY_CI";
case Engine.HIVE:
return "default";
- }
+ case Engine.BIGQUERY:
+ return ""
+ }
return "";
};
diff --git a/frontend/src/utils/v1/instance.ts b/frontend/src/utils/v1/instance.ts
index 0af5ee0409..00465018ed 100644
--- a/frontend/src/utils/v1/instance.ts
+++ b/frontend/src/utils/v1/instance.ts
@@ -3,6 +3,7 @@ import { useI18n } from "vue-i18n";
import { useSubscriptionV1Store } from "@/store";
import type { ComposedInstance } from "@/types";
import { UNKNOWN_ID } from "@/types";
+import {isDev} from "@/utils";
import { Engine, State } from "@/types/proto/v1/common";
import type { Environment } from "@/types/proto/v1/environment_service";
import type { Instance } from "@/types/proto/v1/instance_service";
@@ -99,6 +100,10 @@ export const supportedEngineV1List = () => {
engines.push(Engine.DM);
engines.push(Engine.DORIS);
}
+ if (isDev()) {
+ engines.push(Engine.BIGQUERY);
+
+ }
return engines;
};
@@ -139,6 +144,8 @@ export const instanceV1HasCreateDatabase = (
if (engine === Engine.ORACLE) return false;
if (engine === Engine.DM) return false;
if (engine === Engine.ELASTICSEARCH) return false;
+ if (engine === Engine.SPANNER) return false;
+ if (engine === Engine.BIGQUERY) return false;
return true;
};
@@ -287,7 +294,9 @@ export const engineNameV1 = (type: Engine): string => {
return "Hive";
case Engine.ELASTICSEARCH:
return "Elasticsearch";
- }
+ case Engine.BIGQUERY:
+ return "BigQuery";
+ }
return "";
};