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: add view table definition in table detail drawer (#10950)
boojack6ed461c6f747
diff --git a/frontend/src/components/TableDetailDrawer.vue b/frontend/src/components/TableDetailDrawer.vueindex 0f04422c40..4b8052f74e 100644--- a/frontend/src/components/TableDetailDrawer.vue+++ b/frontend/src/components/TableDetailDrawer.vue@@ -77,6 +77,31 @@:label="true":disabled="!allowQuery"/>+ <NPopover+ trigger="click"+ placement="bottom"+ @update:show="(show: boolean) => show"+ >+ <template #trigger>+ <NButton+ quaternary+ size="tiny"+ class="!px-1"+ v-bind="$attrs"+ >+ <span class="textlabel"+ >{{ $t("database.view-definition") }}+ </span>+ <CodeIcon class="ml-1 w-4 h-4" />+ </NButton>+ </template>+ <TableSchemaViewer+ class="!w-[32rem] !h-[20rem]"+ :database="database"+ :schema="schemaName"+ :table="tableName"+ />+ </NPopover></dl></div></div>@@ -205,7 +230,10 @@<script lang="ts" setup>import { computedAsync } from "@vueuse/core";+import { CodeIcon } from "lucide-vue-next";+import { NButton, NPopover } from "naive-ui";import { computed, reactive, ref } from "vue";+import TableSchemaViewer from "@/components/TableSchemaViewer.vue";import {DatabaseV1Name,InstanceV1Name,diff --git a/frontend/src/components/TableSchemaViewer.vue b/frontend/src/components/TableSchemaViewer.vuenew file mode 100644index 0000000000..e2ad7faffc--- /dev/null+++ b/frontend/src/components/TableSchemaViewer.vue@@ -0,0 +1,170 @@+<template>+ <div+ class="w-full h-auto flex flex-col justify-start items-center"+ v-bind="$attrs"+ >+ <div class="w-full flex flex-row justify-between items-center gap-x-2 mb-2">+ <div class="textlabel flex-1 truncate">+ {{ resourceName }}+ </div>+ <div class="flex flex-row justify-end items-center">+ <NTooltip>+ <template #trigger>+ <NButton+ quaternary+ size="tiny"+ class="!px-1"+ @click="handleCopySchemaString"+ >+ <ClipboardIcon class="w-4 h-4" />+ </NButton>+ </template>+ {{ $t("common.copy") }}+ </NTooltip>+ </div>+ </div>+ <MonacoEditor+ :content="schemaString || ''"+ :readonly="true"+ class="border w-full h-auto grow"+ />+ </div>+</template>++<script lang="ts" setup>+import { useClipboard } from "@vueuse/core";+import { cloneDeep, isUndefined } from "lodash-es";+import { ClipboardIcon } from "lucide-vue-next";+import { NButton, NTooltip } from "naive-ui";+import { onMounted, ref, computed } from "vue";+import { nextTick } from "vue";+import { useI18n } from "vue-i18n";+import { MonacoEditor } from "@/components/MonacoEditor";+import { sqlServiceClient } from "@/grpcweb";+import { pushNotification, useDBSchemaV1Store } from "@/store";+import type { ComposedDatabase } from "@/types";+import { Engine } from "@/types/proto/v1/common";+import {+ DatabaseMetadata,+ DatabaseMetadataView,+ SchemaMetadata,+ TableMetadata,+} from "@/types/proto/v1/database_service";++const props = defineProps<{+ database: ComposedDatabase;+ schema?: string;+ table?: string;+}>();++const { t } = useI18n();+const dbSchemaStore = useDBSchemaV1Store();+const { copy: copyTextToClipboard, isSupported } = useClipboard({+ legacy: true,+});+const schemaString = ref<string | null>(null);++const engine = computed(() => {+ return props.database.instanceEntity.engine;+});++const databaseMetadata = computed(() => {+ return dbSchemaStore.getDatabaseMetadata(props.database.name);+});++const schemaMetadata = computed(() => {+ if (!isUndefined(props.schema)) {+ return databaseMetadata.value?.schemas.find(+ (schema) => schema.name === props.schema+ );+ }+ return null;+});++const tableMetadata = computed(() => {+ if (props.table && schemaMetadata.value) {+ return schemaMetadata.value.tables.find(+ (table) => table.name === props.table+ );+ }+ return null;+});++const resourceName = computed(() => {+ if (props.table) {+ if (hasSchemaProperty.value) {+ return `${props.schema}.${props.table}`;+ } else {+ return props.table;+ }+ }+ if (props.schema) {+ return props.schema;+ }+ return props.database.name;+});++const hasSchemaProperty = computed(() => {+ return (+ engine.value === Engine.POSTGRES ||+ engine.value === Engine.SNOWFLAKE ||+ engine.value === Engine.ORACLE ||+ engine.value === Engine.DM ||+ engine.value === Engine.MSSQL ||+ engine.value === Engine.REDSHIFT ||+ engine.value === Engine.RISINGWAVE+ );+});++onMounted(async () => {+ await dbSchemaStore.getOrFetchDatabaseMetadata({+ database: props.database.name,+ view: DatabaseMetadataView.DATABASE_METADATA_VIEW_FULL,+ silent: true,+ });++ nextTick(async () => {+ const mockedDatabaseMetadata = DatabaseMetadata.fromPartial({+ name: props.database.name,+ });+ if (!isUndefined(props.schema)) {+ const schemaMetadata = SchemaMetadata.fromPartial({+ name: props.schema,+ });+ if (props.table) {+ schemaMetadata.tables = [+ TableMetadata.fromPartial({+ ...cloneDeep(tableMetadata.value),+ foreignKeys: [],+ }),+ ];+ }+ mockedDatabaseMetadata.schemas = [schemaMetadata];+ }++ const { schema } = await sqlServiceClient.stringifyMetadata({+ metadata: mockedDatabaseMetadata,+ engine: engine.value,+ });+ schemaString.value = schema.trim();+ });+});++const handleCopySchemaString = () => {+ if (!isSupported.value) {+ pushNotification({+ module: "bytebase",+ style: "CRITICAL",+ title: "Copy to clipboard is not enabled in your browser.",+ });+ return;+ }++ copyTextToClipboard(schemaString.value || "");+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("sql-editor.copy-success"),+ });+};+</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 41b7261a4a..5ca65a0794 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1749,7 +1749,8 @@"partition-tables": "Partition tables","external-server-name": "External Server Name","external-database-name": "External Database Name",- "foreign-table-detail": "Foreign table detail"+ "foreign-table-detail": "Foreign table detail",+ "view-definition": "View definition"},"repository": {"our-webhook-link": "The webhook created by Bytebase can be found at {webhookLink}.",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 0c241fc332..a88330caac 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1749,7 +1749,8 @@"partition-tables": "Tablas de particiones","external-database-name": "Nombre de la base de datos externa","external-server-name": "Nombre del servidor externo",- "foreign-table-detail": "Detalle de la tabla externa"+ "foreign-table-detail": "Detalle de la tabla externa",+ "view-definition": "Ver definición"},"repository": {"branch-observe-file-change": "La rama donde Bytebase observa el cambio de archivo.",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 769b717e24..37f82faa01 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1749,7 +1749,8 @@"partition-tables": "パーティションテーブル","external-server-name": "外部サーバー名","external-database-name": "外部データベース名",- "foreign-table-detail": "外部テーブルの詳細"+ "foreign-table-detail": "外部テーブルの詳細",+ "view-definition": "ビュー定義"},"repository": {"our-webhook-link": "Bytebaseによって作成されたWebhookは{webhookLink}で見つけることができます。",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 51a70c30dc..6b3736f876 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1749,7 +1749,8 @@"partition-tables": "Bảng phân vùng","external-server-name": "Tên máy chủ bên ngoài","external-database-name": "Tên cơ sở dữ liệu bên ngoài",- "foreign-table-detail": "Chi tiết bảng nước ngoài"+ "foreign-table-detail": "Chi tiết bảng nước ngoài",+ "view-definition": "Xem định nghĩa"},"repository": {"our-webhook-link": "Bạn có thể tìm thấy webhook do Bytebase tạo tại {webhookLink}.",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 6bdaa22187..0bd232f866 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1749,7 +1749,8 @@"partition-tables": "分区表","external-server-name": "外部服务器名称","external-database-name": "外部数据库名称",- "foreign-table-detail": "外部表详情"+ "foreign-table-detail": "外部表详情",+ "view-definition": "查看定义"},"repository": {"branch-observe-file-change": "Bytebase 跟踪文件变更的分支。",diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vueindex d702c3b220..b487e6131f 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/DatabaseSchema.vue@@ -7,7 +7,7 @@@click="handleClickHeader"><heroicons-outline:database class="h-4 w-4 mr-1 flex-shrink-0" />- <span class="text-sm">{{ database.databaseName }}</span>+ <span class="text-sm truncate">{{ database.databaseName }}</span></div><div class="flex justify-end gap-x-0.5"><HideInStandaloneMode>diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/StringifyMetadataButton.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/StringifyMetadataButton.vueindex 026e8e9905..89e6b92e7f 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/StringifyMetadataButton.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/StringifyMetadataButton.vue@@ -2,160 +2,35 @@<NPopovertrigger="click"placement="bottom-end"- @update:show="(show: boolean) => show && handleShowSchemaString()"+ @update:show="(show: boolean) => show"><template #trigger><NButton quaternary size="tiny" class="!px-1" v-bind="$attrs"><CodeIcon class="w-4 h-4" /></NButton></template>- <div class="w-[32rem] h-[20rem] flex flex-col justify-center items-center">- <BBSpin v-if="isFetching" />- <template v-else>- <div- class="w-full flex flex-row justify-between items-center gap-x-2 mb-2"- >- <div class="textlabel flex-1 truncate">- {{ resourceName }}- </div>- <div class="flex flex-row justify-end items-center">- <NTooltip>- <template #trigger>- <NButton- quaternary- size="tiny"- class="!px-1"- @click="handleCopySchemaString"- >- <ClipboardIcon class="w-4 h-4" />- </NButton>- </template>- {{ $t("common.copy") }}- </NTooltip>- </div>- </div>- <MonacoEditor- :content="schemaString || ''"- :readonly="true"- class="border w-full h-full"- />- </template>- </div>+ <TableSchemaViewer+ class="!w-[32rem] !h-[20rem]"+ :database="database"+ :schema="schema?.name"+ :table="table?.name"+ /></NPopover></template><script lang="ts" setup>-import { useClipboard } from "@vueuse/core";-import { cloneDeep } from "lodash-es";-import { CodeIcon, ClipboardIcon } from "lucide-vue-next";-import { NButton, NPopover, NTooltip } from "naive-ui";-import { onMounted, ref, computed } from "vue";-import { useI18n } from "vue-i18n";-import { MonacoEditor } from "@/components/MonacoEditor";-import { sqlServiceClient } from "@/grpcweb";-import { pushNotification, useDBSchemaV1Store } from "@/store";+import { CodeIcon } from "lucide-vue-next";+import { NButton, NPopover } from "naive-ui";+import TableSchemaViewer from "@/components/TableSchemaViewer.vue";import type { ComposedDatabase } from "@/types";-import { Engine } from "@/types/proto/v1/common";import {- DatabaseMetadata,SchemaMetadata,TableMetadata,} from "@/types/proto/v1/database_service";-const props = defineProps<{+defineProps<{database: ComposedDatabase;schema?: SchemaMetadata;table?: TableMetadata;}>();--const { t } = useI18n();-const dbSchemaStore = useDBSchemaV1Store();-const { copy: copyTextToClipboard, isSupported } = useClipboard({- legacy: true,-});-const schemaString = ref<string | null>(null);-const isFetching = ref<boolean>(false);--const engine = computed(() => {- return props.database.instanceEntity.engine;-});--const resourceName = computed(() => {- if (props.table) {- if (hasSchemaProperty.value) {- return `${props.schema?.name}.${props.table.name}`;- } else {- return props.table.name;- }- }- if (props.schema) {- return props.schema.name;- }- return props.database.name;-});--const hasSchemaProperty = computed(() => {- return (- engine.value === Engine.POSTGRES ||- engine.value === Engine.SNOWFLAKE ||- engine.value === Engine.ORACLE ||- engine.value === Engine.DM ||- engine.value === Engine.MSSQL ||- engine.value === Engine.REDSHIFT ||- engine.value === Engine.RISINGWAVE- );-});--onMounted(async () => {- await dbSchemaStore.getOrFetchDatabaseMetadata({- database: props.database.name,- silent: true,- });-});--const handleCopySchemaString = () => {- if (!isSupported.value) {- pushNotification({- module: "bytebase",- style: "CRITICAL",- title: "Copy to clipboard is not enabled in your browser.",- });- return;- }-- copyTextToClipboard(schemaString.value || "");- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("sql-editor.copy-success"),- });-};--const handleShowSchemaString = async () => {- const databaseMetadata = DatabaseMetadata.fromPartial({- name: props.database.name,- });- if (props.schema) {- const schemaMetadata = SchemaMetadata.fromPartial({- name: props.schema.name,- });- if (props.table) {- schemaMetadata.tables = [- TableMetadata.fromPartial({- ...cloneDeep(props.table),- foreignKeys: [],- }),- ];- }- databaseMetadata.schemas = [schemaMetadata];- }-- isFetching.value = true;- const { schema } = await sqlServiceClient.stringifyMetadata({- metadata: databaseMetadata,- engine: engine.value,- });- schemaString.value = schema.trim();- isFetching.value = false;-};</script>diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vueindex 2111576377..35d3554bc4 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableSchema.vue@@ -7,7 +7,7 @@><heroicons-outline:table class="h-4 w-4 mr-1 flex-shrink-0" /><span v-if="schema.name" class="text-sm">{{ schema.name }}.</span>- <span class="text-sm">{{ table.name }}</span>+ <span class="text-sm truncate">{{ table.name }}</span></div><div class="flex justify-end gap-x-0.5">