Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor(frontend): use resource id instead of uid for database (#13301)
boojack8c932759468b
diff --git a/frontend/src/components/AdvancedSearch/ScopeTags.vue b/frontend/src/components/AdvancedSearch/ScopeTags.vueindex 547eaf8c9d..81e8b6079c 100644--- a/frontend/src/components/AdvancedSearch/ScopeTags.vue+++ b/frontend/src/components/AdvancedSearch/ScopeTags.vue@@ -26,7 +26,7 @@ import { computed } from "vue";import { useI18n } from "vue-i18n";import { UNKNOWN_ID } from "@/types";import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";-import { callCssVariable } from "@/utils";+import { callCssVariable, extractDatabaseResourceName } from "@/utils";const props = defineProps<{params: SearchParams;@@ -65,6 +65,9 @@ const renderValue = (scope: SearchScope, index: number) => {if (scope.id === "created") {const [begin, end] = scope.value.split(",").map((ts) => parseInt(ts, 10));return [dayjs(begin).format("L"), dayjs(end).format("L")].join("-");+ } else if (scope.id === "database") {+ const { databaseName } = extractDatabaseResourceName(scope.value);+ return <span>{databaseName}</span>;}if (scope.value === `${UNKNOWN_ID}`) {return <span>{t("common.all").toLocaleLowerCase()}</span>;diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.tsindex fa9ac8f0dc..33c1b5f1de 100644--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts@@ -113,7 +113,7 @@ export const useCommonSearchScopeOptions = (description: t("issue.advanced-search.scope.database.description"),options: databaseList.value.map((db) => {return {- value: `${db.databaseName}-${db.uid}`,+ value: db.name,keywords: [db.databaseName,extractInstanceResourceName(db.instance),@@ -209,8 +209,7 @@ export const useCommonSearchScopeOptions = (return true;}- const uid = option.value.split("-").slice(-1)[0];- const db = databaseV1Store.getDatabaseByUID(uid);+ const db = databaseV1Store.getDatabaseByName(option.value);const project = db.project;const instance = db.instance;diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vueindex d84e85287e..49b73a4157 100644--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue@@ -54,12 +54,12 @@<template #footer><div class="flex-1 flex items-center justify-between"><div>- <NTooltip v-if="flattenSelectedDatabaseUidList.length > 0">+ <NTooltip v-if="flattenSelectedDatabaseNameList.length > 0"><template #trigger><div class="textinfolabel">{{$t("database.selected-n-databases", {- n: flattenSelectedDatabaseUidList.length,+ n: flattenSelectedDatabaseNameList.length,})}}</div>@@ -108,7 +108,7 @@<SchemaEditorModalv-if="state.showSchemaEditorModal"- :database-id-list="schemaEditorContext.databaseIdList"+ :database-names="schemaEditorContext.databaseNameList":alter-type="'MULTI_DB'":plan-only="state.planOnly"@close="state.showSchemaEditorModal = false"@@ -159,7 +159,7 @@ type LocalState = {label: string;showSchemaLessDatabaseList: boolean;selectedLabels: { key: string; value: string }[];- selectedDatabaseUidList: Set<string>;+ selectedDatabaseNames: Set<string>;showSchemaEditorModal: boolean;params: SearchParams;// planOnly is used to indicate whether only to create plan.@@ -198,13 +198,13 @@ const featureModalContext = ref<{}>({});const schemaEditorContext = ref<{- databaseIdList: string[];+ databaseNameList: string[];}>({- databaseIdList: [],+ databaseNameList: [],});const state = reactive<LocalState>({- selectedDatabaseUidList: new Set<string>(),+ selectedDatabaseNames: new Set<string>(),label: "environment",showSchemaLessDatabaseList: false,showSchemaEditorModal: false,@@ -330,13 +330,13 @@ const schemalessDatabaseList = computed(() => {);});-const flattenSelectedDatabaseUidList = computed(() => {- return [...state.selectedDatabaseUidList];+const flattenSelectedDatabaseNameList = computed(() => {+ return [...state.selectedDatabaseNames];});const flattenSelectedProjectList = computed(() => {- const projects = flattenSelectedDatabaseUidList.value.map((uid) => {- return databaseV1Store.getDatabaseByUID(uid).projectEntity;+ const projects = flattenSelectedDatabaseNameList.value.map((name) => {+ return databaseV1Store.getDatabaseByName(name).projectEntity;});return uniqBy(projects, (project) => project.name);});@@ -344,13 +344,13 @@ const flattenSelectedProjectList = computed(() => {const allowGenerateMultiDb = computed(() => {return (flattenSelectedProjectList.value.length === 1 &&- flattenSelectedDatabaseUidList.value.length > 0+ flattenSelectedDatabaseNameList.value.length > 0);});const flattenSelectedDatabaseList = computed(() =>- flattenSelectedDatabaseUidList.value.map(- (id) => selectableDatabaseList.value.find((db) => db.uid === id)!+ flattenSelectedDatabaseNameList.value.map(+ (name) => selectableDatabaseList.value.find((db) => db.name === name)!));@@ -362,8 +362,8 @@ const generateMultiDb = async () => {allowUsingSchemaEditor(flattenSelectedDatabaseList.value) &&!disableSchemaEditor.value) {- schemaEditorContext.value.databaseIdList = [- ...flattenSelectedDatabaseUidList.value,+ schemaEditorContext.value.databaseNameList = [+ ...flattenSelectedDatabaseNameList.value,];state.showSchemaEditorModal = true;return;@@ -401,11 +401,7 @@ const generateMultiDb = async () => {const handleDatabasesSelectionChanged = (selectedDatabaseNameList: Set<string>) => {- state.selectedDatabaseUidList = new Set(- Array.from(selectedDatabaseNameList).map(- (name) => databaseV1Store.getDatabaseByName(name)?.uid- )- );+ state.selectedDatabaseNames = selectedDatabaseNameList;};const cancel = () => {diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vueindex 979c8355f0..3ea544aa46 100644--- a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue@@ -78,14 +78,14 @@<NCheckbox:checked="isDatabaseSelectedForEnvironment(- database.uid,+ database.name,environment.name)"@update:checked="(checked) =>- toggleDatabaseUidForEnvironment(- database.uid,+ toggleDatabaseNameForEnvironment(+ database.name,environment.name,checked)@@ -126,7 +126,7 @@ import type { Project } from "@/types/proto/v1/project_service";import { hostPortOfInstanceV1 } from "@/utils";interface LocalState {- selectedDatabaseUidListForEnvironment: Map<string, string[]>;+ selectedDatabaseNameListForEnvironment: Map<string, string[]>;}const props = defineProps<{@@ -140,17 +140,17 @@ const emit = defineEmits<{}>();const state = reactive<LocalState>({- selectedDatabaseUidListForEnvironment: new Map<string, string[]>(),+ selectedDatabaseNameListForEnvironment: new Map<string, string[]>(),});watch(- () => state.selectedDatabaseUidListForEnvironment,- (selectedDatabaseUidListForEnvironment) => {- const flattenDatabaseIdList: string[] = [];- for (const databaseIdList of selectedDatabaseUidListForEnvironment.values()) {- flattenDatabaseIdList.push(...databaseIdList);+ () => state.selectedDatabaseNameListForEnvironment,+ (selectedDatabaseNameListForEnvironment) => {+ const flattenDatabaseNameList: string[] = [];+ for (const databaseNameList of selectedDatabaseNameListForEnvironment.values()) {+ flattenDatabaseNameList.push(...databaseNameList);}- emit("select-databases", ...flattenDatabaseIdList);+ emit("select-databases", ...flattenDatabaseNameList);},{ deep: true });@@ -169,18 +169,18 @@ const databaseListGroupByEnvironment = computed(() => {return listByEnv.filter((group) => group.databaseList.length > 0);});-const toggleDatabaseUidForEnvironment = (- databaseId: string,+const toggleDatabaseNameForEnvironment = (+ databaseName: string,environmentName: string,selected: boolean) => {- const map = state.selectedDatabaseUidListForEnvironment;+ const map = state.selectedDatabaseNameListForEnvironment;const list = map.get(environmentName) || [];- const index = list.indexOf(databaseId);+ const index = list.indexOf(databaseName);if (selected) {// push the databaseId in if neededif (index < 0) {- list.push(databaseId);+ list.push(databaseName);}} else {// remove the databaseId if exists@@ -197,12 +197,12 @@ const toggleDatabaseUidForEnvironment = (};const isDatabaseSelectedForEnvironment = (- databaseId: string,+ databaseName: string,environmentName: string) => {- const map = state.selectedDatabaseUidListForEnvironment;+ const map = state.selectedDatabaseNameListForEnvironment;const list = map.get(environmentName) || [];- return list.includes(databaseId);+ return list.includes(databaseName);};const getAllSelectionStateForEnvironment = (@@ -210,10 +210,10 @@ const getAllSelectionStateForEnvironment = (databaseList: ComposedDatabase[]): { checked: boolean; indeterminate: boolean } => {const set = new Set(- state.selectedDatabaseUidListForEnvironment.get(environment.name) ?? []+ state.selectedDatabaseNameListForEnvironment.get(environment.name) ?? []);- const checked = set.size > 0 && databaseList.every((db) => set.has(db.uid));- const indeterminate = !checked && databaseList.some((db) => set.has(db.uid));+ const checked = set.size > 0 && databaseList.every((db) => set.has(db.name));+ const indeterminate = !checked && databaseList.some((db) => set.has(db.name));return {checked,@@ -227,7 +227,7 @@ const toggleAllDatabasesSelectionForEnvironment = (on: boolean) => {databaseList.forEach((db) =>- toggleDatabaseUidForEnvironment(db.uid, environment.name, on)+ toggleDatabaseNameForEnvironment(db.name, environment.name, on));};@@ -236,9 +236,9 @@ const getSelectionStateSummaryForEnvironment = (databaseList: ComposedDatabase[]) => {const set = new Set(- state.selectedDatabaseUidListForEnvironment.get(environment.name)+ state.selectedDatabaseNameListForEnvironment.get(environment.name));- const selected = databaseList.filter((db) => set.has(db.uid)).length;+ const selected = databaseList.filter((db) => set.has(db.name)).length;const total = databaseList.length;return { selected, total };diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vueindex 9a1cb1793e..5ab3f987d2 100644--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue@@ -179,7 +179,7 @@ interface LocalState {}const props = defineProps({- databaseIdList: {+ databaseNames: {type: Array as PropType<string[]>,required: true,},@@ -232,8 +232,8 @@ const allowPreviewIssue = computed(() => {});const databaseList = computed(() => {- return props.databaseIdList.map((databaseId) => {- return databaseV1Store.getDatabaseByUID(databaseId);+ return props.databaseNames.map((database) => {+ return databaseV1Store.getDatabaseByName(database);});});// Returns the type if it's uniq.@@ -251,7 +251,7 @@ const project = computed();const editTargetsKey = computed(() => {return JSON.stringify({- databaseIdList: props.databaseIdList,+ databaseNameList: props.databaseNames,alterType: props.alterType,});});diff --git a/frontend/src/components/Branch/BaselineSchemaSelector.vue b/frontend/src/components/Branch/BaselineSchemaSelector.vueindex 75d57c706b..8e5d05a04d 100644--- a/frontend/src/components/Branch/BaselineSchemaSelector.vue+++ b/frontend/src/components/Branch/BaselineSchemaSelector.vue@@ -29,13 +29,13 @@ import { Engine } from "@/types/proto/v1/common";const props = defineProps<{projectName?: string;- databaseId?: string;+ databaseName?: string;readonly?: boolean;loading?: boolean;}>();const emit = defineEmits<{- (event: "update:database-id", databaseId: string | undefined): void;+ (event: "update:database-name", databaseName: string | undefined): void;}>();interface LocalState {@@ -76,7 +76,7 @@ watch(} catch (error) {// do nothing.}- emit("update:database-id", database?.uid);+ emit("update:database-name", database?.name);});diff --git a/frontend/src/components/Branch/BranchCreateView.vue b/frontend/src/components/Branch/BranchCreateView.vueindex 8e282ea3e6..203709bd56 100644--- a/frontend/src/components/Branch/BranchCreateView.vue+++ b/frontend/src/components/Branch/BranchCreateView.vue@@ -61,7 +61,7 @@</div><BaselineSchemaSelectorv-if="source === 'BASELINE'"- v-model:database-id="databaseId"+ v-model:database-name="databaseName":project-name="project.name":loading="isPreparingBranch"/>@@ -110,7 +110,7 @@ import {} from "@/store";import { useBranchStore } from "@/store/modules/branch";import type { ComposedProject } from "@/types";-import { UNKNOWN_ID } from "@/types";+import { unknownDatabase } from "@/types";import { Branch } from "@/types/proto/v1/branch_service";import { DatabaseMetadataView } from "@/types/proto/v1/database_service";import { hasProjectPermissionV2 } from "@/utils";@@ -136,7 +136,7 @@ const databaseStore = useDatabaseV1Store();const branchStore = useBranchStore();const dbSchemaStore = useDBSchemaV1Store();const source = ref<Source>("PARENT");-const databaseId = ref<string>();+const databaseName = ref<string>();const parentBranchName = ref<string>();const isCreating = ref(false);const branchId = ref<string>("");@@ -146,13 +146,13 @@ const EMPTY_BRANCH = Branch.fromPartial({});const allowCreateBranchFromDatabase = computed(() => {return hasProjectPermissionV2(- props.project,- useCurrentUserV1().value,- "bb.branches.admin"- )+ props.project,+ useCurrentUserV1().value,+ "bb.branches.admin"+ );});-const debouncedDatabaseId = useDebounce(databaseId, DEBOUNCE_RATE);+const debouncedDatabaseName = useDebounce(databaseName, DEBOUNCE_RATE);const debouncedParentBranchName = useDebounce(parentBranchName, DEBOUNCE_RATE);const filterParentBranch = (branch: Branch) => {@@ -176,12 +176,12 @@ const prepareBranchFromParentBranch = async (parent: string) => {console.timeEnd(tag);return branch;};-const prepareBranchFromDatabaseHead = async (uid: string) => {- const tag = `prepareBranchFromDatabaseHead(${uid})`;+const prepareBranchFromDatabaseHead = async (databaseName: string) => {+ const tag = `prepareBranchFromDatabaseHead(${databaseName})`;console.time(tag);console.time("--fetch metadata");- const database = databaseStore.getDatabaseByUID(uid);+ const database = databaseStore.getDatabaseByName(databaseName);const metadata = await dbSchemaStore.getOrFetchDatabaseMetadata({database: database.name,view: DatabaseMetadataView.DATABASE_METADATA_VIEW_FULL,@@ -209,14 +209,14 @@ const branchData = shallowRef<BranchData>();const prepareBranch = async (_parentBranchName: string | undefined,- _databaseId: string | undefined+ _databaseName: string | undefined) => {isPreparingBranch.value = true;const finish = (s: BranchData | undefined) => {const isOutdated =_parentBranchName !== parentBranchName.value ||- _databaseId !== databaseId.value;+ _databaseName !== databaseName.value;if (isOutdated) {return;}@@ -232,8 +232,8 @@ const prepareBranch = async (parent: _parentBranchName,});}- if (_databaseId && _databaseId !== String(UNKNOWN_ID)) {- const branch = await prepareBranchFromDatabaseHead(_databaseId);+ if (_databaseName && _databaseName !== unknownDatabase().name) {+ const branch = await prepareBranchFromDatabaseHead(_databaseName);return finish({branch,parent: undefined,@@ -245,16 +245,16 @@ const prepareBranch = async (const handleSwitchSource = (src: Source) => {source.value = src;if (src === "PARENT") {- databaseId.value = undefined;+ databaseName.value = undefined;} else {parentBranchName.value = undefined;}};watch(- [debouncedParentBranchName, debouncedDatabaseId],- ([parentBranchName, databaseId]) => {- prepareBranch(parentBranchName, databaseId);+ [debouncedParentBranchName, debouncedDatabaseName],+ ([parentBranchName, databaseName]) => {+ prepareBranch(parentBranchName, databaseName);});diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vueindex 1853b81df7..7817b796df 100644--- a/frontend/src/components/Branch/BranchDetailView.vue+++ b/frontend/src/components/Branch/BranchDetailView.vue@@ -506,7 +506,7 @@ const handleApplyBranchToDatabase = () => {});};-const handleApplyToDatabase = async (databaseIdList: string[]) => {+const handleApplyToDatabase = async (databaseNameList: string[]) => {const cleanup = () => {state.applyingToDatabaseStatus = false;};@@ -535,8 +535,8 @@ const handleApplyToDatabase = async (databaseIdList: string[]) => {return cleanup();}- const targetDatabaseList = databaseIdList.map((id) =>- databaseStore.getDatabaseByUID(id)+ const targetDatabaseList = databaseNameList.map((name) =>+ databaseStore.getDatabaseByName(name));const query: Record<string, any> = {template: "bb.issue.database.schema.update",diff --git a/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vue b/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vueindex 82946618e1..68266a84d5 100644--- a/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vue+++ b/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vue@@ -11,8 +11,8 @@:database-list="schemaDatabaseList":environment-list="environmentList"@select-databases="- (...dbUidList) =>- (state.selectedDatabaseUidList = new Set(dbUidList))+ (...dbNameList) =>+ (state.selectedDatabaseNameList = new Set(dbNameList))"><template #header>@@ -46,12 +46,12 @@<div class="flex-1 flex items-center justify-between"><div><div- v-if="flattenSelectedDatabaseUidList.length > 0"+ v-if="flattenSelectedDatabaseNameList.length > 0"class="textinfolabel">{{$t("database.selected-n-databases", {- n: flattenSelectedDatabaseUidList.length,+ n: flattenSelectedDatabaseNameList.length,})}}</div>@@ -116,7 +116,7 @@ import { useChangelistDetailContext } from "../context";type LocalState = {keyword: string;isGenerating: boolean;- selectedDatabaseUidList: Set<string>;+ selectedDatabaseNameList: Set<string>;};const { t } = useI18n();@@ -129,7 +129,7 @@ const {} = useChangelistDetailContext();const state = reactive<LocalState>({- selectedDatabaseUidList: new Set<string>(),+ selectedDatabaseNameList: new Set<string>(),keyword: "",isGenerating: false,});@@ -190,14 +190,14 @@ const schemalessDatabaseList = computed(() => {);});-const flattenSelectedDatabaseUidList = computed(() => {- return [...state.selectedDatabaseUidList];+const flattenSelectedDatabaseNameList = computed(() => {+ return [...state.selectedDatabaseNameList];});const nextButtonErrors = computed(() => {const errors: string[] = [];- if (flattenSelectedDatabaseUidList.value.length === 0) {+ if (flattenSelectedDatabaseNameList.value.length === 0) {errors.push(t("changelist.error.select-at-least-one-database"));}return errors;@@ -206,8 +206,8 @@ const nextButtonErrors = computed(() => {const handleClickNext = async () => {state.isGenerating = true;try {- const databaseList = flattenSelectedDatabaseUidList.value.map((uid) =>- databaseStore.getDatabaseByUID(uid)+ const databaseList = flattenSelectedDatabaseNameList.value.map((name) =>+ databaseStore.getDatabaseByName(name));const query: Record<string, any> = {@@ -237,7 +237,7 @@ const handleClickNext = async () => {};const reset = () => {- state.selectedDatabaseUidList = new Set();+ state.selectedDatabaseNameList = new Set();state.keyword = "";};diff --git a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vueindex f42b7f744f..9f39ba03f4 100644--- a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue+++ b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue@@ -51,7 +51,7 @@</NButton><NButtontype="primary"- :disabled="!state.selectedDatabaseUid"+ :disabled="!state.selectedDatabaseName"@click="navigateToIssuePage">{{ $t("common.next") }}@@ -93,7 +93,7 @@ import { DatabaseLabelFilter, DrawerContent } from "../v2";type LocalState = {label: string;- selectedDatabaseUid?: string;+ selectedDatabaseName?: string;selectedLabels: { key: string; value: string }[];params: SearchParams;};@@ -209,18 +209,16 @@ const handleDatabasesSelectionChanged = (if (selectedDatabaseNameList.size !== 1) {return;}- state.selectedDatabaseUid = databaseV1Store.getDatabaseByName(- Array.from(selectedDatabaseNameList)[0]- )?.uid;+ state.selectedDatabaseName = Array.from(selectedDatabaseNameList)[0];};const navigateToIssuePage = async () => {- if (!state.selectedDatabaseUid) {+ if (!state.selectedDatabaseName) {return;}const selectedDatabase = filteredDatabaseList.value.find(- (db) => db.uid === state.selectedDatabaseUid+ (db) => db.name === state.selectedDatabaseName) as ComposedDatabase;const project = selectedDatabase?.projectEntity;diff --git a/frontend/src/components/Database/DatabaseSlowQueryPanel.vue b/frontend/src/components/Database/DatabaseSlowQueryPanel.vueindex 4a7ef0c89c..8bf4c57ab0 100644--- a/frontend/src/components/Database/DatabaseSlowQueryPanel.vue+++ b/frontend/src/components/Database/DatabaseSlowQueryPanel.vue@@ -40,7 +40,7 @@ const readonlyScopes = computed((): SearchScope[] => {},{id: "database",- value: `${props.database.databaseName}-${props.database.uid}`,+ value: props.database.name,},];});diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/index.vueindex 460b435975..1161bbe8dc 100644--- a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue+++ b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue@@ -73,21 +73,16 @@import dayjs from "dayjs";import { isUndefined } from "lodash-es";import { NButton, NInput } from "naive-ui";-import { computed, onMounted, reactive } from "vue";+import { computed, reactive } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import ExpirationSelector from "@/components/ExpirationSelector.vue";import RequiredStar from "@/components/RequiredStar.vue";import { DrawerContent, Drawer } from "@/components/v2";import { issueServiceClient } from "@/grpcweb";-import {- useCurrentUserV1,- useDatabaseV1Store,- useProjectV1Store,- pushNotification,-} from "@/store";+import { useCurrentUserV1, useProjectV1Store, pushNotification } from "@/store";import type { DatabaseResource, ComposedProject } from "@/types";-import { UNKNOWN_ID, PresetRoleType } from "@/types";+import { PresetRoleType } from "@/types";import { Duration } from "@/types/proto/google/protobuf/duration";import { Expr } from "@/types/proto/google/type/expr";import {@@ -100,7 +95,6 @@ import MaxRowCountSelect from "./MaxRowCountSelect.vue";interface LocalState {environmentName?: string;- databaseId?: string;databaseResourceCondition?: string;databaseResources: DatabaseResource[];expireDays: number;@@ -108,13 +102,8 @@ interface LocalState {description: string;}-defineOptions({- name: "RequestExportPanel",-});-const props = defineProps<{projectName: string;- databaseId?: string;redirectToIssuePage?: boolean;}>();@@ -125,7 +114,6 @@ const emit = defineEmits<{const { t } = useI18n();const router = useRouter();const currentUser = useCurrentUserV1();-const databaseStore = useDatabaseV1Store();const projectStore = useProjectV1Store();const state = reactive<LocalState>({databaseResources: [],@@ -141,37 +129,6 @@ const allowCreate = computed(() => {return true;});-onMounted(async () => {- if (props.databaseId) {- handleDatabaseSelect(props.databaseId);- }-});--const handleEnvironmentSelect = (environmentName: string | undefined) => {- state.environmentName = environmentName;- const database = databaseStore.getDatabaseByUID(- state.databaseId || String(UNKNOWN_ID)- );- // Unselect database if it doesn't belong to the newly selected environment.- if (- database &&- database.uid !== String(UNKNOWN_ID) &&- database.effectiveEnvironment !== state.environmentName- ) {- state.databaseId = undefined;- }-};--const handleDatabaseSelect = (databaseId: string | undefined) => {- state.databaseId = databaseId;- const database = databaseStore.getDatabaseByUID(- state.databaseId || String(UNKNOWN_ID)- );- if (database && database.uid !== String(UNKNOWN_ID)) {- handleEnvironmentSelect(database.effectiveEnvironment);- }-};-const doCreateIssue = async () => {if (!allowCreate.value) {return;diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.tsindex 691d706fbc..27688f2f8e 100644--- a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts+++ b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts@@ -217,8 +217,7 @@ export const useIssueSearchScopeOptions = (return true;}- const uid = option.value.split("-").slice(-1)[0];- const db = databaseV1Store.getDatabaseByUID(uid);+ const db = databaseV1Store.getDatabaseByName(option.value);const project = db.project;const instance = db.instance;diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.tsindex 3c3afb2981..66995111cd 100644--- a/frontend/src/components/IssueV1/logic/initialize/create.ts+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts@@ -1,4 +1,4 @@-import { cloneDeep, groupBy, isNaN, isNumber, orderBy } from "lodash-es";+import { cloneDeep, groupBy, orderBy } from "lodash-es";import { v4 as uuidv4 } from "uuid";import { reactive } from "vue";import { useRoute } from "vue-router";@@ -19,7 +19,6 @@ import {emptyIssue,isValidProjectName,TaskTypeListWithStatement,- UNKNOWN_ID,} from "@/types";import { DatabaseConfig } from "@/types/proto/v1/database_service";import { IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";@@ -53,7 +52,7 @@ export type InitialSQL = {};type CreateIssueParams = {- databaseUIDList: string[];+ databaseNameList: string[];project: ComposedProject;query: Record<string, string>;initialSQL: InitialSQL;@@ -68,12 +67,11 @@ export const createIssueSkeleton = async (const project = await useProjectV1Store().getOrFetchProjectByName(`${projectNamePrefix}${projectName}`);- const databaseIdList = (query.databaseList ?? "").split(",");- const databaseUIDList = await prepareDatabaseUIDList(databaseIdList);- await prepareDatabaseList(databaseUIDList, project.name);+ const databaseNameList = (query.databaseList ?? "").split(",");+ await prepareDatabaseList(databaseNameList, project.name);const params: CreateIssueParams = {- databaseUIDList,+ databaseNameList,project,query,initialSQL: extractInitialSQLFromQuery(query),@@ -131,7 +129,7 @@ const buildIssue = async (params: CreateIssueParams) => {};export const buildPlan = async (params: CreateIssueParams) => {- const { databaseUIDList, project, query } = params;+ const { databaseNameList, project, query } = params;const plan = Plan.fromJSON({uid: nextUID(),@@ -140,7 +138,7 @@ export const buildPlan = async (params: CreateIssueParams) => {if (query.changelist) {// build plan for changelistplan.steps = await buildStepsViaChangelist(- databaseUIDList,+ databaseNameList,query.changelist,params);@@ -154,18 +152,18 @@ export const buildPlan = async (params: CreateIssueParams) => {// Use dedicated sheets if sqlMap is specified.// Share ONE sheet if otherwise.const sheetUID = hasInitialSQL(params.initialSQL) ? undefined : nextUID();- plan.steps = await buildSteps(databaseUIDList, params, sheetUID);+ plan.steps = await buildSteps(databaseNameList, params, sheetUID);}return plan;};export const buildSteps = async (- databaseUIDList: string[],+ databaseNameList: string[],params: CreateIssueParams,sheetUID?: string // if specified, all tasks will share the same sheet) => {- const databaseList = databaseUIDList.map((uid) =>- useDatabaseV1Store().getDatabaseByUID(uid)+ const databaseList = databaseNameList.map((name) =>+ useDatabaseV1Store().getDatabaseByName(name));const databaseListGroupByEnvironment = groupBy(@@ -226,7 +224,7 @@ export const buildStepsForDatabaseGroup = async (};export const buildStepsViaChangelist = async (- databaseUIDList: string[],+ databaseNameList: string[],changelistResourceName: string,params: CreateIssueParams) => {@@ -235,8 +233,8 @@ export const buildStepsViaChangelist = async ();const { changes } = changelist;- const databaseList = databaseUIDList.map((uid) =>- useDatabaseV1Store().getDatabaseByUID(uid)+ const databaseList = databaseNameList.map((name) =>+ useDatabaseV1Store().getDatabaseByName(name));const databaseListGroupByEnvironment = groupBy(@@ -486,27 +484,27 @@ const hasInitialSQL = (initialSQL?: InitialSQL) => {};export const prepareDatabaseList = async (- databaseUIDList: string[],+ databaseNameList: string[],projectName: string) => {const databaseStore = useDatabaseV1Store();if (isValidProjectName(projectName)) {// For preparing the database if user visits creating issue url directly.- // It's horrible to fetchDatabaseByUID one-by-one when query.databaseList+ // It's horrible to fetchDatabaseByName one-by-one when query.databaseList// is big (100+ sometimes)// So we are fetching databaseList by project since that's better cached.const project =await useProjectV1Store().getOrFetchProjectByName(projectName);await prepareDatabaseListByProject(project.name);} else {- // Otherwise, we don't have the projectUID (very rare to see, theoretically)+ // Otherwise, we don't have the projectName (very rare to see, theoretically)// so we need to fetch the first database in databaseList by id,// and see what project it belongs.- if (databaseUIDList.length > 0) {- const firstDB = await databaseStore.getOrFetchDatabaseByUID(- databaseUIDList[0]+ if (databaseNameList.length > 0) {+ const firstDB = await databaseStore.getOrFetchDatabaseByName(+ databaseNameList[0]);- if (databaseUIDList.length > 1) {+ if (databaseNameList.length > 1) {await prepareDatabaseListByProject(firstDB.project);}}@@ -569,28 +567,3 @@ export const isValidSpec = (spec: Plan_Spec): boolean => {}return true;};--const prepareDatabaseUIDList = async (- // databaseIdList is a list of database identifiers. Including UID and resource id.- // e.g. ["103", "205", "instances/mysql/databases/employee"]- databaseIdList: string[]-) => {- const databaseStore = useDatabaseV1Store();- const databaseUIDList = [];- for (const maybeUID of databaseIdList) {- if (!maybeUID || maybeUID === String(UNKNOWN_ID)) {- continue;- }- const uid = Number(maybeUID);- if (isNumber(uid) && !isNaN(uid)) {- databaseUIDList.push(maybeUID);- continue;- }- const database = await databaseStore.getOrFetchDatabaseByName(- maybeUID,- true // silent- );- databaseUIDList.push(database.uid);- }- return databaseUIDList.filter((id) => id && id !== String(UNKNOWN_ID));-};diff --git a/frontend/src/components/Plan/logic/initialize/create.ts b/frontend/src/components/Plan/logic/initialize/create.tsindex 9fa4fe79e6..02ac116786 100644--- a/frontend/src/components/Plan/logic/initialize/create.ts+++ b/frontend/src/components/Plan/logic/initialize/create.ts@@ -1,4 +1,4 @@-import { cloneDeep, groupBy, isNaN, isNumber, orderBy } from "lodash-es";+import { cloneDeep, groupBy, orderBy } from "lodash-es";import { v4 as uuidv4 } from "uuid";import { useRoute } from "vue-router";import type { TemplateType } from "@/plugins";@@ -13,7 +13,7 @@ import {import { projectNamePrefix } from "@/store/modules/v1/common";import { composePlan } from "@/store/modules/v1/plan";import type { ComposedProject } from "@/types";-import { isValidProjectName, UNKNOWN_ID } from "@/types";+import { isValidProjectName } from "@/types";import { DatabaseConfig } from "@/types/proto/v1/database_service";import {Plan,@@ -38,7 +38,7 @@ export type InitialSQL = {};type CreatePlanParams = {- databaseUIDList: string[];+ databaseNameList: string[];project: ComposedProject;query: Record<string, string>;initialSQL: InitialSQL;@@ -60,12 +60,11 @@ export const createPlanSkeleton = async (const project = await useProjectV1Store().getOrFetchProjectByName(`${projectNamePrefix}${projectName}`);- const databaseIdList = (query.databaseList ?? "").split(",");- const databaseUIDList = await prepareDatabaseUIDList(databaseIdList);- await prepareDatabaseList(databaseUIDList, project.name);+ const databaseNameList = (query.databaseList ?? "").split(",");+ await prepareDatabaseList(databaseNameList, project.name);const params: CreatePlanParams = {- databaseUIDList,+ databaseNameList,project,query,initialSQL: extractInitialSQLFromQuery(query),@@ -85,7 +84,7 @@ const prepareParamsContext = async (params: CreatePlanParams) => {};export const buildPlan = async (params: CreatePlanParams) => {- const { databaseUIDList, project, query } = params;+ const { databaseNameList, project, query } = params;const plan = Plan.fromJSON({uid: nextUID(),@@ -96,7 +95,7 @@ export const buildPlan = async (params: CreatePlanParams) => {if (query.changelist) {// build plan for changelistplan.steps = await buildStepsViaChangelist(- databaseUIDList,+ databaseNameList,query.changelist,params);@@ -110,18 +109,18 @@ export const buildPlan = async (params: CreatePlanParams) => {// Use dedicated sheets if sqlMap is specified.// Share ONE sheet if otherwise.const sheetUID = hasInitialSQL(params.initialSQL) ? undefined : nextUID();- plan.steps = await buildSteps(databaseUIDList, params, sheetUID);+ plan.steps = await buildSteps(databaseNameList, params, sheetUID);}return await composePlan(plan);};export const buildSteps = async (- databaseUIDList: string[],+ databaseNameList: string[],params: CreatePlanParams,sheetUID?: string // if specified, all specs will share the same sheet) => {- const databaseList = databaseUIDList.map((uid) =>- useDatabaseV1Store().getDatabaseByUID(uid)+ const databaseList = databaseNameList.map((name) =>+ useDatabaseV1Store().getDatabaseByName(name));const databaseListGroupByEnvironment = groupBy(@@ -189,7 +188,7 @@ export const buildStepsForDatabaseGroup = async (};export const buildStepsViaChangelist = async (- databaseUIDList: string[],+ databaseNameList: string[],changelistResourceName: string,params: CreatePlanParams) => {@@ -198,8 +197,8 @@ export const buildStepsViaChangelist = async ();const { changes } = changelist;- const databaseList = databaseUIDList.map((uid) =>- useDatabaseV1Store().getDatabaseByUID(uid)+ const databaseList = databaseNameList.map((name) =>+ useDatabaseV1Store().getDatabaseByName(name));const databaseListGroupByEnvironment = groupBy(@@ -409,27 +408,27 @@ const hasInitialSQL = (initialSQL?: InitialSQL) => {};export const prepareDatabaseList = async (- databaseUIDList: string[],+ databaseNameList: string[],projectName: string) => {const databaseStore = useDatabaseV1Store();if (isValidProjectName(projectName)) {// For preparing the database if user visits creating plan url directly.- // It's horrible to fetchDatabaseByUID one-by-one when query.databaseList+ // It's horrible to fetchDatabaseByName one-by-one when query.databaseList// is big (100+ sometimes)// So we are fetching databaseList by project since that's better cached.const project =await useProjectV1Store().getOrFetchProjectByName(projectName);await prepareDatabaseListByProject(project.name);} else {- // Otherwise, we don't have the projectUID (very rare to see, theoretically)+ // Otherwise, we don't have the projectName (very rare to see, theoretically)// so we need to fetch the first database in databaseList by id,// and see what project it belongs.- if (databaseUIDList.length > 0) {- const firstDB = await databaseStore.getOrFetchDatabaseByUID(- databaseUIDList[0]+ if (databaseNameList.length > 0) {+ const firstDB = await databaseStore.getOrFetchDatabaseByName(+ databaseNameList[0]);- if (databaseUIDList.length > 1) {+ if (databaseNameList.length > 1) {await prepareDatabaseListByProject(firstDB.project);}}@@ -464,28 +463,3 @@ export const isValidSpec = (spec: Plan_Spec): boolean => {}return true;};--const prepareDatabaseUIDList = async (- // databaseIdList is a list of database identifiers. Including UID and resource id.- // e.g. ["103", "205", "instances/mysql/databases/employee"]- databaseIdList: string[]-) => {- const databaseStore = useDatabaseV1Store();- const databaseUIDList = [];- for (const maybeUID of databaseIdList) {- if (!maybeUID || maybeUID === String(UNKNOWN_ID)) {- continue;- }- const uid = Number(maybeUID);- if (isNumber(uid) && !isNaN(uid)) {- databaseUIDList.push(maybeUID);- continue;- }- const database = await databaseStore.getOrFetchDatabaseByName(- maybeUID,- true // silent- );- databaseUIDList.push(database.uid);- }- return databaseUIDList.filter((id) => id && id !== String(UNKNOWN_ID));-};diff --git a/frontend/src/components/SensitiveData/SensitiveColumnView.vue b/frontend/src/components/SensitiveData/SensitiveColumnView.vueindex f8546d8b3e..cffe7749a4 100644--- a/frontend/src/components/SensitiveData/SensitiveColumnView.vue+++ b/frontend/src/components/SensitiveData/SensitiveColumnView.vue@@ -217,12 +217,12 @@ const hasPermission = computed(() => {const updateList = async () => {state.isLoading = true;- const distinctDatabaseIdList = uniq(+ const distinctDatabaseUIDList = uniq(policyList.value.map((policy) => policy.resourceUid));// Fetch or get all needed databasesawait Promise.all(- distinctDatabaseIdList.map((databaseId) =>+ distinctDatabaseUIDList.map((databaseId) =>databaseStore.getOrFetchDatabaseByUID(databaseId)));diff --git a/frontend/src/components/SlowQuery/Panel/types.ts b/frontend/src/components/SlowQuery/Panel/types.tsindex 9739eb1a84..e91acd4de3 100644--- a/frontend/src/components/SlowQuery/Panel/types.ts+++ b/frontend/src/components/SlowQuery/Panel/types.ts@@ -1,6 +1,6 @@import dayjs from "dayjs";import { useDatabaseV1Store } from "@/store";-import { UNKNOWN_ID } from "@/types";+import { unknownDatabase } from "@/types";import { ListSlowQueriesRequest } from "@/types/proto/v1/database_service";import type { SearchScope } from "@/utils";@@ -18,9 +18,8 @@ export const buildListSlowQueriesRequest = (const query: string[] = [];request.parent = `projects/${project}`;if (database) {- const uid = database.split("-").slice(-1)[0];- const db = useDatabaseV1Store().getDatabaseByUID(uid);- if (db.uid !== `${UNKNOWN_ID}`) {+ const db = useDatabaseV1Store().getDatabaseByName(database);+ if (db.name !== unknownDatabase().name) {query.push(`database = "${db.name}"`);}} else if (environment) {diff --git a/frontend/src/components/TransferDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm.vueindex f5ce8e4790..0f73bcc654 100644--- a/frontend/src/components/TransferDatabaseForm.vue+++ b/frontend/src/components/TransferDatabaseForm.vue@@ -25,7 +25,7 @@/><MultipleDatabaseSelectorv-if="filteredDatabaseList.length > 0"- v-model:selected-uid-list="state.selectedDatabaseUidList"+ v-model:selected-database-name-list="state.selectedDatabaseNameList":transfer-source="state.transferSource":database-list="filteredDatabaseList"/>@@ -35,12 +35,12 @@<template #footer><div class="flex-1 flex items-center justify-between">- <NTooltip :disabled="state.selectedDatabaseUidList.length === 0">+ <NTooltip :disabled="state.selectedDatabaseNameList.length === 0"><template #trigger><div class="textinfolabel">{{$t("database.selected-n-databases", {- n: state.selectedDatabaseUidList.length,+ n: state.selectedDatabaseNameList.length,})}}</div>@@ -110,7 +110,7 @@ interface LocalState {projectFilter: Project | undefined;searchText: string;loading: boolean;- selectedDatabaseUidList: string[];+ selectedDatabaseNameList: string[];}const props = defineProps<{@@ -143,7 +143,7 @@ const state = reactive<LocalState>({projectFilter: undefined,searchText: "",loading: false,- selectedDatabaseUidList: [],+ selectedDatabaseNameList: [],});const { project } = useProjectByName(toRef(props, "projectName"));@@ -211,11 +211,11 @@ const filteredDatabaseList = computed(() => {return sortDatabaseV1List(list);});-const allowTransfer = computed(() => state.selectedDatabaseUidList.length > 0);+const allowTransfer = computed(() => state.selectedDatabaseNameList.length > 0);const selectedDatabaseList = computed(() =>- state.selectedDatabaseUidList.map((uid) =>- databaseStore.getDatabaseByUID(uid)+ state.selectedDatabaseNameList.map((name) =>+ databaseStore.getDatabaseByName(name)));diff --git a/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue b/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vueindex 5d77511c0f..bb10b00ebe 100644--- a/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue+++ b/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue@@ -63,13 +63,13 @@<NCheckbox:checked="isDatabaseSelectedForEnvironment(- database.uid,+ database.name,environment.name)"@update:checked="- toggleDatabaseIdForEnvironment(- database.uid,+ toggleDatabaseNameForEnvironment(+ database.name,environment.name,$event)@@ -116,71 +116,75 @@ import { InstanceV1Name, ProductionEnvironmentV1Icon } from "../v2";import type { TransferSource } from "./utils";type LocalState = {- selectedDatabaseUidListForEnvironment: Map<string, Set<string>>;+ selectedDatabaseNameListForEnvironment: Map<string, Set<string>>;};const props = withDefaults(defineProps<{transferSource: TransferSource;databaseList: ComposedDatabase[];- selectedUidList?: string[];+ selectedDatabaseNameList?: string[];}>(),{- selectedUidList: () => [],+ selectedDatabaseNameList: () => [],});const emit = defineEmits<{- (e: "update:selectedUidList", uidList: string[]): void;+ (e: "update:selectedDatabaseNameList", databaseNameList: string[]): void;}>();const environmentList = useEnvironmentV1List();const state = reactive<LocalState>({- selectedDatabaseUidListForEnvironment: new Map(),+ selectedDatabaseNameListForEnvironment: new Map(),});-const toggleDatabaseIdForEnvironment = (- databaseId: string,+const toggleDatabaseNameForEnvironment = (+ databaseName: string,environmentName: string,selected: boolean) => {- const map = state.selectedDatabaseUidListForEnvironment;+ const map = state.selectedDatabaseNameListForEnvironment;const set = map.get(environmentName) || new Set();if (selected) {- set.add(databaseId);+ set.add(databaseName);} else {- set.delete(databaseId);+ set.delete(databaseName);}map.set(environmentName, set);};watch(- () => [props.databaseList, props.selectedUidList],+ () => [props.databaseList, props.selectedDatabaseNameList],(args) => {- const [databaseList, selectedUidList] = args as [+ const [databaseList, selectedDatabaseNameList] = args as [ComposedDatabase[],string[],];- for (const uid of selectedUidList) {- const database = databaseList.find((db) => db.uid === uid);+ for (const name of selectedDatabaseNameList) {+ const database = databaseList.find((db) => db.name === name);if (!database) {continue;}- toggleDatabaseIdForEnvironment(uid, database.effectiveEnvironment, true);+ toggleDatabaseNameForEnvironment(+ name,+ database.effectiveEnvironment,+ true+ );}},{ immediate: true });watch(- () => state.selectedDatabaseUidListForEnvironment,+ () => state.selectedDatabaseNameListForEnvironment,(map) => {const list: string[] = [];for (const listForEnv of map.values()) {list.push(...listForEnv);}- emit("update:selectedUidList", list);+ emit("update:selectedDatabaseNameList", list);},{ deep: true });@@ -224,18 +228,18 @@ const databaseListGroupByEnvironment = computed(() => {watch(() => props.transferSource,() => {- // Clear selected database ID list when transferSource changed.- state.selectedDatabaseUidListForEnvironment.clear();+ // Clear selected database name list when transferSource changed.+ state.selectedDatabaseNameListForEnvironment.clear();});const isDatabaseSelectedForEnvironment = (- databaseId: string,+ databaseName: string,environmentName: string) => {- const map = state.selectedDatabaseUidListForEnvironment;+ const map = state.selectedDatabaseNameListForEnvironment;const set = map.get(environmentName) || new Set();- return set.has(databaseId);+ return set.has(databaseName);};const getAllSelectionStateForEnvironment = (@@ -243,10 +247,10 @@ const getAllSelectionStateForEnvironment = (databaseList: ComposedDatabase[]): { checked: boolean; indeterminate: boolean } => {const set =- state.selectedDatabaseUidListForEnvironment.get(environment.name) ??+ state.selectedDatabaseNameListForEnvironment.get(environment.name) ??new Set();- const checked = set.size > 0 && databaseList.every((db) => set.has(db.uid));- const indeterminate = !checked && databaseList.some((db) => set.has(db.uid));+ const checked = set.size > 0 && databaseList.every((db) => set.has(db.name));+ const indeterminate = !checked && databaseList.some((db) => set.has(db.name));return {checked,@@ -260,7 +264,7 @@ const toggleAllDatabasesSelectionForEnvironment = (on: boolean) => {databaseList.forEach((db) =>- toggleDatabaseIdForEnvironment(db.uid, environment.name, on)+ toggleDatabaseNameForEnvironment(db.name, environment.name, on));};@@ -269,20 +273,19 @@ const getSelectionStateSummaryForEnvironment = (databaseList: ComposedDatabase[]) => {const set =- state.selectedDatabaseUidListForEnvironment.get(environment.name) ||+ state.selectedDatabaseNameListForEnvironment.get(environment.name) ||new Set();- const selected = databaseList.filter((db) => set.has(db.uid)).length;+ const selected = databaseList.filter((db) => set.has(db.name)).length;const total = databaseList.length;-return { selected, total };};const handleClickRow = (db: ComposedDatabase) => {const environmentName = db.effectiveEnvironment;- toggleDatabaseIdForEnvironment(- db.uid,+ toggleDatabaseNameForEnvironment(+ db.name,environmentName,- !isDatabaseSelectedForEnvironment(db.uid, environmentName)+ !isDatabaseSelectedForEnvironment(db.name, environmentName));};</script>diff --git a/frontend/src/components/TransferOutDatabaseForm/Label.vue b/frontend/src/components/TransferOutDatabaseForm/Label.vuedeleted file mode 100644index 10502c4781..0000000000--- a/frontend/src/components/TransferOutDatabaseForm/Label.vue+++ /dev/null@@ -1,59 +0,0 @@-<template>- <EnvironmentV1Name- v-if="environment"- :environment="environment"- :link="false"- />- <template v-if="database">- <div class="flex items-center gap-x-1">- <!-- eslint-disable-next-line vue/no-v-html -->- <span class="truncate" v-html="databaseName" />- -<InstanceV1Name- :instance="database.instanceResource"- :link="false"- class="whitespace-nowrap"- />- </div>- </template>-</template>--<script setup lang="ts">-import { escape } from "lodash-es";-import { computed } from "vue";-import { EnvironmentV1Name, InstanceV1Name } from "@/components/v2";-import { useDatabaseV1Store, useEnvironmentV1Store } from "@/store";-import { getHighlightHTMLByRegExp } from "@/utils";-import type { DatabaseTreeOption } from "./common";--const props = defineProps<{- option: DatabaseTreeOption;- keyword?: string;-}>();--const id = computed(() => {- return props.option.value.split("-").pop()!;-});--const environment = computed(() => {- const { option } = props;- if (option.level !== "environment") return undefined;- return useEnvironmentV1Store().getEnvironmentByUID(id.value);-});--const database = computed(() => {- const { option } = props;- if (option.level !== "database") return undefined;- return useDatabaseV1Store().getDatabaseByUID(id.value);-});--const databaseName = computed(() => {- const name = database.value?.databaseName ?? "";- const keyword = (props.keyword ?? "").trim();-- return getHighlightHTMLByRegExp(- escape(name),- escape(keyword),- false /* !caseSensitive */- );-});-</script>diff --git a/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vue b/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vueindex 84cdcd5577..d6b2d53292 100644--- a/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vue+++ b/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vue@@ -16,7 +16,7 @@<span class="text-red-500">*</span></span><MultipleDatabaseSelector- v-model:selected-uid-list="selectedUidList"+ v-model:selected-database-name-list="selectedDatabaseNameList":transfer-source="'OTHER'":database-list="[...databaseList]"/>@@ -91,7 +91,7 @@ import { MultipleDatabaseSelector } from "../TransferDatabaseForm";const props = defineProps<{databaseList: ComposedDatabase[];- selectedDatabaseUidList?: string[];+ selectedDatabaseNames?: string[];}>();const emit = defineEmits<{@@ -105,17 +105,19 @@ const loading = ref(false);const transfer = ref<"project" | "unassign">("project");const router = useRouter();-const selectedUidList = ref<string[]>(props.selectedDatabaseUidList ?? []);+const selectedDatabaseNameList = ref<string[]>(+ props.selectedDatabaseNames ?? []+);watch(- () => props.selectedDatabaseUidList ?? [],- (list) => (selectedUidList.value = list),+ () => props.selectedDatabaseNames ?? [],+ (list) => (selectedDatabaseNameList.value = list),{ immediate: true });const selectedDatabaseList = computed(() => {- return selectedUidList.value.map((uid) => {- return databaseStore.getDatabaseByUID(uid);+ return selectedDatabaseNameList.value.map((name) => {+ return databaseStore.getDatabaseByName(name);});});@@ -149,7 +151,7 @@ const validationErrors = computed(() => {if (!targetProject.value) {errors.push(t("database.transfer.errors.select-target-project"));}- if (selectedUidList.value.length === 0) {+ if (selectedDatabaseNameList.value.length === 0) {errors.push(t("database.transfer.errors.select-at-least-one-database"));}return errors;diff --git a/frontend/src/components/TransferOutDatabaseForm/common.ts b/frontend/src/components/TransferOutDatabaseForm/common.tsdeleted file mode 100644index b74a2b35b9..0000000000--- a/frontend/src/components/TransferOutDatabaseForm/common.ts+++ /dev/null@@ -1,54 +0,0 @@-import { groupBy } from "lodash-es";-import type { TransferOption, TreeOption } from "naive-ui";-import { useEnvironmentV1Store } from "@/store";-import type { ComposedDatabase } from "@/types";--export interface DatabaseTreeOption<L = "environment" | "database">- extends TreeOption {- level: L;- value: string;-}--const databaseValuePrefix = "database-";--export const getDatabaseTreeValue = (databaseUid: string) =>- `${databaseValuePrefix}${databaseUid}`;--export const isDatabaseTreeValue = (value: string) =>- value.startsWith(databaseValuePrefix);--export const mapTreeOptions = (databaseList: ComposedDatabase[]) => {- const environmentV1Store = useEnvironmentV1Store();- const databaseListGroupByEnvironment = groupBy(- databaseList,- (db) => db.effectiveEnvironment- );- return Object.keys(databaseListGroupByEnvironment).map<- DatabaseTreeOption<"environment">- >((environmentName) => {- const environment =- environmentV1Store.getEnvironmentByName(environmentName);- const group = databaseListGroupByEnvironment[environmentName];- const children = group.map<DatabaseTreeOption<"database">>((db) => ({- level: "database",- value: getDatabaseTreeValue(db.uid),- label: db.name,- isLeaf: true,- }));- return {- level: "environment",- value: `environment-${environment?.uid}`,- label: environment?.title,- children,- };- });-};--export const flattenTreeOptions = (options: DatabaseTreeOption[]) => {- return options.flatMap((option) => {- return [- option as TransferOption,- ...((option.children as TransferOption[] | undefined) ?? []),- ];- });-};diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vueindex 7ba2a9bf28..cd9ed8f20e 100644--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue@@ -35,7 +35,7 @@<SchemaEditorModalv-if="state.showSchemaEditorModal"- :database-id-list="schemaEditorContext.databaseIdList"+ :database-names="selectedDatabaseNameList":alter-type="'MULTI_DB'"@close="state.showSchemaEditorModal = false"/>@@ -60,7 +60,7 @@><TransferOutDatabaseForm:database-list="props.databases"- :selected-database-uid-list="selectedDatabaseUidList"+ :selected-database-names="selectedDatabaseNameList"@dismiss="state.showTransferOutDatabaseForm = false"/></Drawer>@@ -93,7 +93,7 @@ import {} from "lucide-vue-next";import { NButton, NTooltip } from "naive-ui";import type { VNode } from "vue";-import { computed, h, reactive, ref } from "vue";+import { computed, h, reactive } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import { BBAlert } from "@/bbkit";@@ -160,11 +160,6 @@ const state = reactive<LocalState>({showLabelEditorDrawer: false,showTransferOutDatabaseForm: false,});-const schemaEditorContext = ref<{- databaseIdList: string[];-}>({- databaseIdList: [],-});const { t } = useI18n();const router = useRouter();@@ -287,8 +282,8 @@ const allowSyncDatabases = computed(() => {});});-const selectedDatabaseUidList = computed(() => {- return props.databases.map((db) => db.uid);+const selectedDatabaseNameList = computed(() => {+ return props.databases.map((db) => db.name);});const generateMultiDb = async (@@ -303,9 +298,6 @@ const generateMultiDb = async (allowUsingSchemaEditor(props.databases) &&!disableSchemaEditor.value) {- schemaEditorContext.value.databaseIdList = [- ...selectedDatabaseUidList.value,- ];state.showSchemaEditorModal = true;return;}diff --git a/frontend/src/utils/v1/advanced-search/issue/utils.ts b/frontend/src/utils/v1/advanced-search/issue/utils.tsindex 99e99838ee..954fc50ba1 100644--- a/frontend/src/utils/v1/advanced-search/issue/utils.ts+++ b/frontend/src/utils/v1/advanced-search/issue/utils.ts@@ -1,6 +1,6 @@import { useDatabaseV1Store } from "@/store";import type { IssueFilter } from "@/types";-import { UNKNOWN_ID } from "@/types";+import { unknownDatabase } from "@/types";import { IssueStatus } from "@/types/proto/v1/issue_service";import type { SearchParams, SemanticIssueStatus } from "../common";import {@@ -19,9 +19,8 @@ export const buildIssueFilterBySearchParams = (let database = "";if (databaseScope) {- const uid = databaseScope.value.split("-").slice(-1)[0];- const db = useDatabaseV1Store().getDatabaseByUID(uid);- if (db.uid !== `${UNKNOWN_ID}`) {+ const db = useDatabaseV1Store().getDatabaseByName(databaseScope.value);+ if (db.name !== unknownDatabase().name) {database = db.name;}}diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vueindex ad7e57a15f..d129f22d7e 100644--- a/frontend/src/views/DatabaseDetail.vue+++ b/frontend/src/views/DatabaseDetail.vue@@ -172,14 +172,14 @@><TransferOutDatabaseForm:database-list="[database]"- :selected-database-uid-list="[database.uid]"+ :selected-database-names="[database.name]"@dismiss="state.showTransferDatabaseModal = false"/></Drawer><SchemaEditorModalv-if="state.showSchemaEditorModal"- :database-id-list="[database.uid]"+ :database-names="[database.name]"alter-type="SINGLE_DB"@close="state.showSchemaEditorModal = false"/>@@ -283,7 +283,9 @@ const {allowListChangeHistories,allowListSlowQueries,} = useDatabaseDetailContext();-const disableSchemaEditor = useAppFeature("bb.feature.issue.disable-schema-editor");+const disableSchemaEditor = useAppFeature(+ "bb.feature.issue.disable-schema-editor"+);onMounted(async () => {anomalyList.value = await useAnomalyV1Store().fetchAnomalyList({diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsxindex b644c1668b..f1e5cae7c1 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx@@ -201,7 +201,7 @@ export const useDropdown = () => {icon: () => <SquarePenIcon class="w-4 h-4" />,onSelect: () => {editorEvents.emit("alter-schema", {- databaseUID: db.uid,+ databaseName: db.name,schema: schema.name,table: table.name,});diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsx b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsxindex efc943fc4e..4393ca5204 100644--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsx+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsx@@ -143,7 +143,7 @@ export const useDropdown = () => {onSelect: () => {const db = node.meta.target as ComposedDatabase;editorEvents.emit("alter-schema", {- databaseUID: db.uid,+ databaseName: db.name,schema: "",table: "",});diff --git a/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue b/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vueindex 785d40e7f1..2477a793d0 100644--- a/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue@@ -6,7 +6,7 @@v-if="currentTab &&isValidInstanceName(instance.name) &&- database.uid !== String(UNKNOWN_ID)+ database.name !== unknownDatabase().name"class="flex justify-start items-center h-8 px-1 whitespace-nowrap shrink-0 gap-x-2">@@ -108,7 +108,7 @@ import {useSQLEditorStore,useSQLEditorTabStore,} from "@/store";-import { UNKNOWN_ID, isValidInstanceName } from "@/types";+import { isValidInstanceName, unknownDatabase } from "@/types";import { EnvironmentTier } from "@/types/proto/v1/environment_service";import { useSQLEditorContext } from "../context";import BatchQueryDatabasesSelector from "./BatchQueryDatabasesSelector.vue";@@ -150,8 +150,7 @@ const showBatchQuerySelector = computed(() => {return (tab &&// Only show entry when user selected a database.- database.value.uid !== String(UNKNOWN_ID) &&- // TODO(steven): implement batch query in admin mode.+ database.value.name !== unknownDatabase().name &&tab.mode !== "ADMIN");});diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vueindex 4769efab8a..89d1c2482e 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vue@@ -19,7 +19,7 @@ import { NButton } from "naive-ui";import { computed, ref } from "vue";import RequestQueryPanel from "@/components/Issue/panel/RequestQueryPanel/index.vue";import { useCurrentUserV1 } from "@/store";-import { UNKNOWN_ID, type ComposedDatabase } from "@/types";+import { unknownDatabase, type ComposedDatabase } from "@/types";import { hasPermissionToCreateRequestGrantIssue } from "@/utils";const props = withDefaults(@@ -38,7 +38,7 @@ const me = useCurrentUserV1();const showPanel = ref(false);const available = computed(() => {- if (props.database.uid === String(UNKNOWN_ID)) {+ if (props.database.name === unknownDatabase().name) {return false;}diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vueindex 58fa350eff..d8099bb464 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue@@ -204,7 +204,7 @@ import type {SQLEditorQueryParams,SQLResultSetV1,} from "@/types";-import { UNKNOWN_ID, isValidInstanceName } from "@/types";+import { isValidInstanceName, unknownDatabase } from "@/types";import { ExportFormat } from "@/types/proto/v1/common";import { Engine } from "@/types/proto/v1/common";import type {@@ -308,7 +308,7 @@ const allowToRequestExportData = computed(() => {if (!database) {return false;}- if (database.uid === String(UNKNOWN_ID)) {+ if (database.name === unknownDatabase().name) {return false;}@@ -415,11 +415,11 @@ const handleExportBtnClick = async (// otherwise the query is executed on instance level, we should use the// `instanceId` from the tab's connection attributesconst database =- props.database && props.database.uid !== String(UNKNOWN_ID)+ props.database && props.database.name !== unknownDatabase().name? props.database.name: "";const instance =- props.database && props.database.uid !== String(UNKNOWN_ID)+ props.database && props.database.name !== unknownDatabase().name? props.database.instance: connectedInstance.value.name;const statement = props.result.statement;diff --git a/frontend/src/views/sql-editor/SQLEditorHomePage.vue b/frontend/src/views/sql-editor/SQLEditorHomePage.vueindex 12d4098cb2..7e6bef4bf6 100644--- a/frontend/src/views/sql-editor/SQLEditorHomePage.vue+++ b/frontend/src/views/sql-editor/SQLEditorHomePage.vue@@ -61,14 +61,6 @@</DrawerContent></Drawer>- <SchemaEditorModal- v-if="alterSchemaState.showModal"- :database-id-list="alterSchemaState.databaseIdList"- :new-window="true"- alter-type="SINGLE_DB"- @close="alterSchemaState.showModal = false"- />-<teleport to="#sql-editor-debug"><li>[Page]isDisconnected: {{ isDisconnected }}</li><li>[Page]currentTab.id: {{ currentTab?.id }}</li>@@ -86,7 +78,6 @@ import { Splitpanes, Pane } from "splitpanes";import { computed, reactive } from "vue";import { useRouter } from "vue-router";import { BBSpin } from "@/bbkit";-import SchemaEditorModal from "@/components/AlterSchemaPrepForm/SchemaEditorModal.vue";import Quickstart from "@/components/Quickstart.vue";import { Drawer, DrawerContent } from "@/components/v2";import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";@@ -96,7 +87,7 @@ import {useDatabaseV1Store,useSQLEditorTabStore,} from "@/store";-import { allowUsingSchemaEditor, extractProjectResourceName } from "@/utils";+import { extractProjectResourceName } from "@/utils";import AsidePanel from "./AsidePanel";import ConnectionPanel from "./ConnectionPanel";import { ConnectionPathBar } from "./EditorCommon";@@ -111,11 +102,6 @@ type LocalState = {sidebarExpanded: boolean;};-type AlterSchemaState = {- showModal: boolean;- databaseIdList: string[];-};-const state = reactive<LocalState>({sidebarExpanded: false,});@@ -132,45 +118,34 @@ const isFetchingSheet = computed(() => false /* editorStore.isFetchingSheet */);const { width: windowWidth } = useWindowSize();-const alterSchemaState = reactive<AlterSchemaState>({- showModal: false,- databaseIdList: [],-});-useEmitteryEventListener(editorEvents,"alter-schema",- ({ databaseUID, schema, table }) => {- const database = databaseStore.getDatabaseByUID(databaseUID);- if (allowUsingSchemaEditor([database])) {- // TODO: support open selected database tab directly in Schema Editor.- alterSchemaState.databaseIdList = [databaseUID];- alterSchemaState.showModal = true;- } else {- const exampleSQL = ["ALTER TABLE"];- if (table) {- if (schema) {- exampleSQL.push(`${schema}.${table}`);- } else {- exampleSQL.push(`${table}`);- }+ ({ databaseName, schema, table }) => {+ const database = databaseStore.getDatabaseByName(databaseName);+ const exampleSQL = ["ALTER TABLE"];+ if (table) {+ if (schema) {+ exampleSQL.push(`${schema}.${table}`);+ } else {+ exampleSQL.push(`${table}`);}- const query = {- template: "bb.issue.database.schema.update",- name: `[${database.databaseName}] Edit schema`,- databaseList: database.name,- sql: exampleSQL.join(" "),- };- const route = router.resolve({- name: PROJECT_V1_ROUTE_ISSUE_DETAIL,- params: {- projectId: extractProjectResourceName(database.project),- issueSlug: "create",- },- query,- });- window.open(route.fullPath, "_blank");}+ const query = {+ template: "bb.issue.database.schema.update",+ name: `[${database.databaseName}] Edit schema`,+ databaseList: database.name,+ sql: exampleSQL.join(" "),+ };+ const route = router.resolve({+ name: PROJECT_V1_ROUTE_ISSUE_DETAIL,+ params: {+ projectId: extractProjectResourceName(database.project),+ issueSlug: "create",+ },+ query,+ });+ window.open(route.fullPath, "_blank");});diff --git a/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vue b/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vueindex e9dcc28f8e..33a62767bc 100644--- a/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vue+++ b/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vue@@ -35,7 +35,7 @@ import {EnvironmentV1Name,} from "@/components/v2";import { useDatabaseV1Store, useEnvironmentV1Store } from "@/store";-import { UNKNOWN_ID, unknownEnvironment } from "@/types";+import { unknownDatabase, unknownEnvironment } from "@/types";import type { Worksheet } from "@/types/proto/v1/worksheet_service";const props = defineProps<{@@ -47,7 +47,7 @@ const database = computed(() => {const { sheet } = props;if (!props.sheet.database) return undefined;const db = databaseStore.getDatabaseByName(sheet.database);- if (db.uid === String(UNKNOWN_ID)) return undefined;+ if (db.name === unknownDatabase().name) return undefined;return db;});diff --git a/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vue b/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vueindex 650329628a..d89df37350 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vue@@ -8,7 +8,7 @@<heroicons-solid:chevron-right class="flex-shrink-0 h-4 w-4 opacity-70" /><span>{{ instance.title }}</span></template>- <template v-if="database.uid !== String(UNKNOWN_ID)">+ <template v-if="database.name !== unknownDatabase().name"><heroicons-solid:chevron-right class="flex-shrink-0 h-4 w-4 opacity-70" /><span>{{ database.databaseName }}</span></template>@@ -21,7 +21,7 @@ import { computed } from "vue";import { EnvironmentV1Name } from "@/components/v2";import { useDatabaseV1Store } from "@/store";import type { SQLEditorTab } from "@/types";-import { UNKNOWN_ID, isValidInstanceName } from "@/types";+import { isValidInstanceName, unknownDatabase } from "@/types";const props = defineProps({tab: {diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.tsindex 9bdf0bdda6..5865af6561 100644--- a/frontend/src/views/sql-editor/context.ts+++ b/frontend/src/views/sql-editor/context.ts@@ -15,7 +15,8 @@ type SQLEditorEvents = Emittery<{mask?: Array<keyof Worksheet>;};"alter-schema": {- databaseUID: string;+ // Format: instances/{instance}/databases/{database}+ databaseName: string;schema: string;table: string;};