Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: change connection in admin mode (#17054)
ecmadaoc3d2f73c15c3
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex 0d9bacd0d6..1f9f000544 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -83,7 +83,9 @@ func NewSQLService(func (s *SQLService) AdminExecute(ctx context.Context, stream *connect.BidiStream[v1pb.AdminExecuteRequest, v1pb.AdminExecuteResponse]) error {var driver db.Drivervar conn *sql.Conn- defer func() {+ var connectionName string++ clean := func() {if conn != nil {if err := conn.Close(); err != nil {slog.Warn("failed to close connection", log.BBError(err))@@ -92,7 +94,8 @@ func (s *SQLService) AdminExecute(ctx context.Context, stream *connect.BidiStreaif driver != nil {driver.Close(ctx)}- }()+ }+ defer clean()for {request, err := stream.Receive()if err != nil {@@ -108,7 +111,9 @@ func (s *SQLService) AdminExecute(ctx context.Context, stream *connect.BidiStrea}// We only need to get the driver and connection once.- if driver == nil {+ if driver == nil || connectionName != request.Name {+ clean()+ connectionName = request.Namedriver, err = s.dbFactory.GetAdminDatabaseDriver(ctx, instance, database, db.ConnectionContext{})if err != nil {return connect.NewError(connect.CodeInternal, errors.Errorf("failed to get database driver: %v", err))@@ -146,6 +151,10 @@ func (s *SQLService) AdminExecute(ctx context.Context, stream *connect.BidiStrea}} else {response.Results = result+ for _, result := range response.Results {+ // The AdminExecute requires bb.sql.admin permission, so we can presume the users have enough permission to export.+ result.AllowExport = true+ }}if err := stream.Send(response); err != nil {diff --git a/backend/tests/sensitive_data_test.go b/backend/tests/sensitive_data_test.goindex daab393232..a3d07591cb 100644--- a/backend/tests/sensitive_data_test.go+++ b/backend/tests/sensitive_data_test.go@@ -77,8 +77,9 @@ var (},},},- Statement: "SELECT * FROM tech_book",- RowsCount: 3,+ Statement: "SELECT * FROM tech_book",+ RowsCount: 3,+ AllowExport: true,})diff --git a/backend/tests/sql_editor_test.go b/backend/tests/sql_editor_test.goindex 1a9baec23b..83ad5b9907 100644--- a/backend/tests/sql_editor_test.go+++ b/backend/tests/sql_editor_test.go@@ -40,8 +40,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},},- Statement: "INSERT INTO tbl VALUES(1);",- RowsCount: 1,+ Statement: "INSERT INTO tbl VALUES(1);",+ RowsCount: 1,+ AllowExport: true,},},},@@ -61,8 +62,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},},- Statement: "INSERT INTO tbl VALUES(1);",- RowsCount: 1,+ Statement: "INSERT INTO tbl VALUES(1);",+ RowsCount: 1,+ AllowExport: true,},{ColumnNames: []string{"Affected Rows"},@@ -74,8 +76,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},},- Statement: " DELETE FROM tbl WHERE id = 1;",- RowsCount: 1,+ Statement: " DELETE FROM tbl WHERE id = 1;",+ RowsCount: 1,+ AllowExport: true,},},},@@ -95,8 +98,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},},- Statement: "INSERT INTO tbl VALUES(1),(2);",- RowsCount: 1,+ Statement: "INSERT INTO tbl VALUES(1),(2);",+ RowsCount: 1,+ AllowExport: true,},},},@@ -116,8 +120,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},},- Statement: "ALTER TABLE tbl ADD COLUMN name VARCHAR(255);",- RowsCount: 1,+ Statement: "ALTER TABLE tbl ADD COLUMN name VARCHAR(255);",+ RowsCount: 1,+ AllowExport: true,},},},diff --git a/backend/tests/sql_export_test.go b/backend/tests/sql_export_test.goindex f8ddf4c63d..53846df3c9 100644--- a/backend/tests/sql_export_test.go+++ b/backend/tests/sql_export_test.go@@ -52,8 +52,9 @@ func TestSQLExport(t *testing.T) {},},},- Statement: "INSERT INTO Test1.tbl (id, name, gender, height) VALUES(1, 'Alice', B'0', B'01111111');",- RowsCount: 1,+ Statement: "INSERT INTO Test1.tbl (id, name, gender, height) VALUES(1, 'Alice', B'0', B'01111111');",+ RowsCount: 1,+ AllowExport: true,},},resetResult: []*v1pb.QueryResult{@@ -67,7 +68,8 @@ func TestSQLExport(t *testing.T) {},},},- RowsCount: 1,+ RowsCount: 1,+ AllowExport: true,},},},@@ -90,7 +92,8 @@ func TestSQLExport(t *testing.T) {},},},- RowsCount: 1,+ RowsCount: 1,+ AllowExport: true,},},resetResult: []*v1pb.QueryResult{@@ -104,7 +107,8 @@ func TestSQLExport(t *testing.T) {},},},- RowsCount: 1,+ RowsCount: 1,+ AllowExport: true,},},},diff --git a/frontend/src/store/modules/sqlEditor/webTerminal.ts b/frontend/src/store/modules/sqlEditor/webTerminal.tsindex 4d008bc6db..52e724042a 100644--- a/frontend/src/store/modules/sqlEditor/webTerminal.ts+++ b/frontend/src/store/modules/sqlEditor/webTerminal.ts@@ -1,7 +1,7 @@import { create, fromJson, toJson } from "@bufbuild/protobuf";import { Code, ConnectError } from "@connectrpc/connect";import Emittery from "emittery";-import { uniqueId } from "lodash-es";+import { uniqueId, cloneDeep } from "lodash-es";import { defineStore } from "pinia";import type { Subscription } from "rxjs";import { fromEventPattern, map, Observable } from "rxjs";@@ -247,7 +247,7 @@ const useQueryStateLogic = (qs: WebTerminalQueryState) => {qs.controller.events.on("query", (input) => {qs.timer.start();- activeQuery().params = input;+ activeQuery().params = cloneDeep(input);activeQuery().status = "RUNNING";});diff --git a/frontend/src/views/ExportCenter/index.vue b/frontend/src/views/ExportCenter/index.vueindex 9c49386daa..3e02375bce 100644--- a/frontend/src/views/ExportCenter/index.vue+++ b/frontend/src/views/ExportCenter/index.vue@@ -200,10 +200,6 @@ watch(useRefreshIssueList(() => issuePagedTable.value?.refresh());const allowExportData = computed(() => {- if (specificProject.value) {- return hasPermissionToCreateDataExportIssueInProject(specificProject.value);- }-return hasPermissionToCreateDataExportIssueInProject(specificProject.value);});</script>diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vueindex 2d3fdcc16d..5f6c119b80 100644--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue@@ -453,7 +453,7 @@ const connect = (node: SQLEditorTreeNode) => {setConnection(node, {extra: {worksheet: tabStore.currentTab?.worksheet ?? "",- mode: DEFAULT_SQL_EDITOR_TAB_MODE,+ mode: tabStore.currentTab?.mode ?? DEFAULT_SQL_EDITOR_TAB_MODE,},context: editorContext,});diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vueindex e98e624274..0bea73e5e4 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue@@ -115,7 +115,7 @@/><divv-if="columnIndex === 0 && !selectionDisabled"- class="absolute inset-y-0 left-0 w-3 cursor-pointer bg-accent/5 hover:bg-accent/10 dark:hover:bg-accent/40"+ class="absolute inset-y-0 left-0 w-3 cursor-pointer bg-accent/5 dark:bg-white/10 hover:bg-accent/10 dark:hover:bg-accent/40":class="{'!bg-accent/10 dark:!bg-accent/40':selectionState.columns.length === 0 &&diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vueindex 2ead13b774..f171c11a08 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue@@ -143,17 +143,20 @@<divclass="w-full flex items-center justify-between text-xs mt-1 gap-x-4 text-control-light">- <NTooltip :disabled="!isSupported">- <template #trigger>- <div- class="truncate cursor-pointer hover:bg-gray-200"- @click="copyStatement"- >- {{ result.statement }}- </div>- </template>- {{ $t("common.click-to-copy") }}- </NTooltip>+ <div class="flex flex-1 items-center space-x-2">+ <RichDatabaseName :database="database" />+ <NTooltip :disabled="!isSupported">+ <template #trigger>+ <div+ class="truncate cursor-pointer hover:bg-gray-200"+ @click="copyStatement"+ >+ {{ result.statement }}+ </div>+ </template>+ {{ $t("common.click-to-copy") }}+ </NTooltip>+ </div><div class="shrink-0 space-x-2"><NButtonv-if="showVisualizeButton"@@ -217,6 +220,7 @@ import type {} from "@/components/DataExportButton.vue";import DataExportButton from "@/components/DataExportButton.vue";import DatabaseInfo from "@/components/DatabaseInfo.vue";+import { RichDatabaseName } from "@/components/v2";import { DISMISS_PLACEHOLDER } from "@/plugins/ai/components/state";import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";import {@@ -250,7 +254,7 @@ import {extractProjectResourceName,extractSQLRowValuePlain,generateIssueTitle,- hasPermissionToCreateRequestGrantIssue,+ hasPermissionToCreateDataExportIssue,instanceV1HasStructuredQueryResult,isNullOrUndefined,} from "@/utils";@@ -365,7 +369,7 @@ const allowToRequestExportData = computed(() => {return false;}- return hasPermissionToCreateRequestGrantIssue(database);+ return hasPermissionToCreateDataExportIssue(database);});// use a debounced value to improve performance when typing rapidlydiff --git a/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vueindex 5d2f6b50f3..e95ec12902 100644--- a/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vue+++ b/frontend/src/views/sql-editor/EditorPanel/TerminalPanel/CompactSQLEditor.vue@@ -57,16 +57,10 @@ import {checkIsEnterEndsStatement,} from "./utils";-const props = defineProps({- content: {- type: String,- default: "",- },- readonly: {- type: Boolean,- default: false,- },-});+const props = defineProps<{+ content: string;+ readonly: boolean;+}>();const emit = defineEmits<{(e: "update:content", content: string): void;@@ -239,7 +233,7 @@ const handleEditorReady = (_: MonacoModule, editor: IStandaloneCodeEditor) => {},// Tell the editor this should be only// triggered when both of the two conditions are satisfied.- "!readonly && cursorAtFirstLine && editorTextFocus && !suggestWidgetVisible && !renameInputVisible && !inSnippetMode && !quickFixWidgetVisible"+ "!readonly && !content && editorTextFocus && !suggestWidgetVisible && !renameInputVisible && !inSnippetMode && !quickFixWidgetVisible");editor.addCommand(monaco.KeyCode.DownArrow,@@ -267,6 +261,10 @@ const handleEditorReady = (_: MonacoModule, editor: IStandaloneCodeEditor) => {},{ immediate: true });++ if (!props.readonly) {+ nextTick(() => editor.focus());+ }};useEmitteryEventListener(editorEvents, "format-content", () => {