Skip to content

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

Add data source list directly to the database detail

天舟4b54fa2ce603
diff --git a/frontend/src/components/DataSourceConnectionPanel.vue b/frontend/src/components/DataSourceConnectionPanel.vue
new file mode 100644
index 0000000000..8d1f439922
--- /dev/null
+++ b/frontend/src/components/DataSourceConnectionPanel.vue
@@ -0,0 +1,269 @@
+<template>
+ <!-- Description list -->
+ <dl class="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2">
+ <div class="sm:col-span-2">
+ <div class="flex items-center space-x-1">
+ <dt class="text-sm font-medium text-control-light">
+ Connection string
+ </dt>
+ <button
+ class="btn-icon"
+ @click.prevent="state.showPassword = !state.showPassword"
+ >
+ <svg
+ v-if="state.showPassword"
+ class="w-5 h-5"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"
+ ></path>
+ </svg>
+ <svg
+ v-else
+ class="w-5 h-5"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
+ ></path>
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
+ ></path>
+ </svg>
+ </button>
+ </div>
+ <dd class="mt-2 text-sm text-main">
+ <div class="space-y-4">
+ <div
+ class="flex"
+ v-for="(connection, index) in connectionStringList"
+ :key="index"
+ >
+ <span
+ class="whitespace-nowrap inline-flex items-center px-3 rounded-l-md border border-l border-r-0 border-control-border bg-gray-50 text-control-light sm:text-sm"
+ >
+ {{ connection.name }}
+ </span>
+ <span
+ class="flex-1 min-w-0 w-full inline-flex items-center px-3 py-2 border border-r border-control-border bg-gray-50 sm:text-sm"
+ >
+ {{ connection.value }}
+ </span>
+ <button
+ class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium text-control-light bg-gray-50 hover:bg-gray-100 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"
+ @click.prevent="copyText(connection)"
+ >
+ <svg
+ class="w-6 h-6"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"
+ ></path>
+ </svg>
+ </button>
+ </div>
+ </div>
+ </dd>
+ </div>
+
+ <div class="sm:col-span-1">
+ <dt class="text-sm font-medium text-control-light">Username</dt>
+ <dd class="mt-1 text-sm text-main">
+ <input
+ v-if="editing"
+ required
+ id="username"
+ type="text"
+ class="textfield"
+ v-model="dataSource.username"
+ />
+ <div v-else class="mt-2.5 mb-3">
+ {{ dataSource.username }}
+ </div>
+ </dd>
+ </div>
+
+ <div class="sm:col-span-1">
+ <div class="flex items-center space-x-1">
+ <dt class="text-sm font-medium text-control-light">Password</dt>
+ </div>
+ <dd class="mt-1 text-sm text-main">
+ <input
+ v-if="editing"
+ required
+ autocomplete="off"
+ id="password"
+ :type="state.showPassword ? 'text' : 'password'"
+ class="textfield"
+ v-model="dataSource.password"
+ />
+ <div v-else class="mt-2.5 mb-3">
+ <template v-if="state.showPassword">
+ {{ dataSource.password }}
+ </template>
+ <template v-else> ****** </template>
+ </div>
+ </dd>
+ </div>
+
+ <div class="sm:col-span-1">
+ <dt class="text-sm font-medium text-control-light">Updated</dt>
+ <dd class="mt-1 text-sm text-main">
+ {{ humanizeTs(dataSource.lastUpdatedTs) }}
+ </dd>
+ </div>
+
+ <div class="sm:col-span-1">
+ <dt class="text-sm font-medium text-control-light">Created</dt>
+ <dd class="mt-1 text-sm text-main">
+ {{ humanizeTs(dataSource.createdTs) }}
+ </dd>
+ </div>
+ </dl>
+</template>
+
+<script lang="ts">
+import { computed, reactive, PropType } from "vue";
+import { useStore } from "vuex";
+import { useRouter } from "vue-router";
+import { toClipboard } from "@soerenmartius/vue3-clipboard";
+import { DataSource, ALL_DATABASE_NAME } from "../types";
+
+type Connection = {
+ name: string;
+ value: string;
+};
+
+interface LocalState {
+ showPassword: boolean;
+}
+
+export default {
+ name: "DataSourceConnectionPanel",
+ components: {},
+ props: {
+ editing: {
+ default: false,
+ type: Boolean,
+ },
+ dataSource: {
+ required: true,
+ type: Object as PropType<DataSource>,
+ },
+ },
+ setup(props, ctx) {
+ const store = useStore();
+ const router = useRouter();
+
+ const state = reactive<LocalState>({
+ showPassword: false,
+ });
+
+ const instance = computed(() => {
+ return store.getters["instance/instanceById"](
+ props.dataSource.instanceId
+ );
+ });
+
+ const database = computed(() => {
+ return store.getters["database/databaseById"](
+ props.dataSource.databaseId,
+ props.dataSource.instanceId
+ );
+ });
+
+ const connectionStringList = computed<Connection[]>(() => {
+ // If host starts with "/", we assume it's a local socket.
+ const isSocket = instance.value.host.startsWith("/");
+ const cliOptionList = isSocket
+ ? [`mysql -S ${instance.value.host}`]
+ : [`mysql -h ${instance.value.host}`];
+ if (instance.value.port) {
+ cliOptionList.push(`-P ${instance.value.port}`);
+ }
+ if (database.value.name != ALL_DATABASE_NAME) {
+ cliOptionList.push(`-D ${database.value.name}`);
+ }
+ if (props.dataSource.username) {
+ cliOptionList.push(`-u ${props.dataSource.username}`);
+ }
+ if (props.dataSource.password) {
+ if (state.showPassword) {
+ cliOptionList.push(`-p${props.dataSource.password}`);
+ } else {
+ cliOptionList.push(`-p`);
+ }
+ }
+
+ let jdbcString = `JDBC can't connect to socket ${instance.value.host} `;
+ if (!isSocket) {
+ jdbcString = `jdbc:mysql://${instance.value.host}`;
+ if (instance.value.port) {
+ jdbcString += `:${instance.value.port}`;
+ }
+ if (database.value.name != ALL_DATABASE_NAME) {
+ jdbcString += `/${database.value.name}`;
+ }
+ const optionList = [];
+ if (props.dataSource.username) {
+ optionList.push(`user=${props.dataSource.username}`);
+ }
+ if (props.dataSource.password) {
+ if (state.showPassword) {
+ optionList.push(`password=${props.dataSource.password}`);
+ } else {
+ optionList.push(`password=******`);
+ }
+ }
+ if (optionList.length > 0) {
+ jdbcString += `&${optionList.join("&")}`;
+ }
+ }
+
+ return [
+ { name: "CLI", value: cliOptionList.join(" ") },
+ { name: "JDBC", value: jdbcString },
+ ];
+ });
+
+ const copyText = (connection: Connection) => {
+ toClipboard(connection.value).then(() => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "INFO",
+ title: `${connection.name} string copied to clipboard.`,
+ });
+ });
+ };
+
+ return {
+ state,
+ connectionStringList,
+ copyText,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/main.js b/frontend/src/main.js
index f24f6a8b63..756003629d 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -39,6 +39,7 @@ import {
urlfy,
instanceSlug,
databaseSlug,
+ dataSourceSlug,
} from "./utils";
if (isDevOrDemo()) {
@@ -58,6 +59,7 @@ app.config.globalProperties.sizeToFit = sizeToFit;
app.config.globalProperties.urlfy = urlfy;
app.config.globalProperties.instanceSlug = instanceSlug;
app.config.globalProperties.databaseSlug = databaseSlug;
+app.config.globalProperties.dataSourceSlug = dataSourceSlug;
app
// Need to use a directive on the element.
diff --git a/frontend/src/views/DataSourceDetail.vue b/frontend/src/views/DataSourceDetail.vue
index 773f3ed107..2236933b71 100644
--- a/frontend/src/views/DataSourceDetail.vue
+++ b/frontend/src/views/DataSourceDetail.vue
@@ -153,149 +153,10 @@
class="max-w-6xl mx-auto px-6 space-y-6 divide-y divide-block-border"
>
<!-- Description list -->
- <dl class="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2">
- <div class="sm:col-span-2">
- <dt class="text-sm font-medium text-control-light">
- Connection string
- </dt>
- <dd class="mt-2 text-sm text-main">
- <div class="space-y-4">
- <div
- class="flex"
- v-for="(connection, index) in connectionStringList"
- :key="index"
- >
- <span
- class="whitespace-nowrap inline-flex items-center px-3 rounded-l-md border border-l border-r-0 border-control-border bg-gray-50 text-control-light sm:text-sm"
- >
- {{ connection.name }}
- </span>
- <span
- class="flex-1 min-w-0 block w-full inline-flex items-center px-3 py-2 border border-r border-control-border bg-gray-50 sm:text-sm"
- >
- {{ connection.value }}
- </span>
- <button
- class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium text-control-light bg-gray-50 hover:bg-gray-100 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"
- @click.prevent="copyText(connection)"
- >
- <svg
- class="w-6 h-6"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"
- ></path>
- </svg>
- </button>
- </div>
- </div>
- </dd>
- </div>
-
- <div class="sm:col-span-1">
- <dt class="text-sm font-medium text-control-light">
- Username<span v-if="state.editing" class="text-red-600">*</span>
- </dt>
- <dd class="mt-1 text-sm text-main">
- <input
- v-if="state.editing"
- required
- id="username"
- type="text"
- class="textfield"
- v-model="state.editingDataSource.username"
- />
- <div v-else class="mt-2.5 mb-3">
- {{ dataSource.username }}
- </div>
- </dd>
- </div>
-
- <div class="sm:col-span-1">
- <div class="flex items-center space-x-1">
- <dt class="text-sm font-medium text-control-light">Password</dt>
- <button
- class="btn-icon"
- @click.prevent="state.showPassword = !state.showPassword"
- >
- <svg
- v-if="state.showPassword"
- class="w-5 h-5"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"
- ></path>
- </svg>
- <svg
- v-else
- class="w-5 h-5"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
- ></path>
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
- ></path>
- </svg>
- </button>
- </div>
- <dd class="mt-1 text-sm text-main">
- <input
- v-if="state.editing"
- required
- autocomplete="off"
- id="password"
- :type="state.showPassword ? 'text' : 'password'"
- class="textfield"
- v-model="state.editingDataSource.password"
- />
- <div v-else class="mt-2.5 mb-3">
- <template v-if="state.showPassword">
- {{ dataSource.password }}
- </template>
- <template v-else> ****** </template>
- </div>
- </dd>
- </div>
-
- <div class="sm:col-span-1">
- <dt class="text-sm font-medium text-control-light">Updated</dt>
- <dd class="mt-1 text-sm text-main">
- {{ humanizeTs(dataSource.lastUpdatedTs) }}
- </dd>
- </div>
-
- <div class="sm:col-span-1">
- <dt class="text-sm font-medium text-control-light">Created</dt>
- <dd class="mt-1 text-sm text-main">
- {{ humanizeTs(dataSource.createdTs) }}
- </dd>
- </div>
- </dl>
+ <DataSourceConnectionPanel
+ :editing="state.editing"
+ :dataSource="state.editing ? state.editingDataSource : dataSource"
+ />
<!-- Guard against dataSource.id != '-1', this could happen when we delete the data source -->
<DataSourceMemberTable
@@ -327,15 +188,10 @@ import { useStore } from "vuex";
import { useRouter } from "vue-router";
import cloneDeep from "lodash-es/cloneDeep";
import isEqual from "lodash-es/isEqual";
-import { toClipboard } from "@soerenmartius/vue3-clipboard";
+import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";
import DataSourceMemberTable from "../components/DataSourceMemberTable.vue";
import { idFromSlug } from "../utils";
-import { ALL_DATABASE_NAME, DataSource } from "../types";
-
-type Connection = {
- name: string;
- value: string;
-};
+import { DataSource } from "../types";
interface LocalState {
editing: boolean;
@@ -355,7 +211,7 @@ export default {
type: String,
},
},
- components: { DataSourceMemberTable },
+ components: { DataSourceConnectionPanel, DataSourceMemberTable },
setup(props, ctx) {
const editNameTextField = ref();
@@ -390,60 +246,6 @@ export default {
);
});
- const connectionStringList = computed<Connection[]>(() => {
- // If host starts with "/", we assume it's a local socket.
- const isSocket = instance.value.host.startsWith("/");
- const cliOptionList = isSocket
- ? [`mysql -S ${instance.value.host}`]
- : [`mysql -h ${instance.value.host}`];
- if (instance.value.port) {
- cliOptionList.push(`-P ${instance.value.port}`);
- }
- if (database.value.name != ALL_DATABASE_NAME) {
- cliOptionList.push(`-D ${database.value.name}`);
- }
- if (dataSource.value.username) {
- cliOptionList.push(`-u ${dataSource.value.username}`);
- }
- if (dataSource.value.password) {
- if (state.showPassword) {
- cliOptionList.push(`-p${dataSource.value.password}`);
- } else {
- cliOptionList.push(`-p`);
- }
- }
-
- let jdbcString = `JDBC can't connect to socket ${instance.value.host} `;
- if (!isSocket) {
- jdbcString = `jdbc:mysql://${instance.value.host}`;
- if (instance.value.port) {
- jdbcString += `:${instance.value.port}`;
- }
- if (database.value.name != ALL_DATABASE_NAME) {
- jdbcString += `/${database.value.name}`;
- }
- const optionList = [];
- if (dataSource.value.username) {
- optionList.push(`user=${dataSource.value.username}`);
- }
- if (dataSource.value.password) {
- if (state.showPassword) {
- optionList.push(`password=${dataSource.value.password}`);
- } else {
- optionList.push(`password=******`);
- }
- }
- if (optionList.length > 0) {
- jdbcString += `&${optionList.join("&")}`;
- }
- }
-
- return [
- { name: "CLI", value: cliOptionList.join(" ") },
- { name: "JDBC", value: jdbcString },
- ];
- });
-
const allowEdit = computed(() => {
return (
currentUser.value.role == "OWNER" || currentUser.value.role == "DBA"
@@ -504,30 +306,18 @@ export default {
});
};
- const copyText = (connection: Connection) => {
- toClipboard(connection.value).then(() => {
- store.dispatch("notification/pushNotification", {
- module: "bytebase",
- style: "INFO",
- title: `${connection.name} string copied to clipboard.`,
- });
- });
- };
-
return {
editNameTextField,
state,
dataSource,
instance,
database,
- connectionStringList,
allowEdit,
allowSave,
editDataSource,
cancelEdit,
saveEdit,
doDelete,
- copyText,
};
},
};
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index 7cde190a41..f6814611bd 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -94,6 +94,46 @@
<div class="pt-6">
<DataSourceTable :instance="instance" :database="database" />
</div>
+
+ <template
+ v-for="(item, index) of [
+ { type: 'RW', list: readWriteDataSourceList },
+ { type: 'RO', list: readOnlyDataSourceList },
+ ]"
+ :key="index"
+ >
+ <div v-if="item.list.length" class="pt-6">
+ <div
+ v-data-source-type
+ class="text-lg leading-6 font-medium text-main mb-4"
+ >
+ {{ item.type }}
+ </div>
+ <div class="space-y-4">
+ <div v-for="(ds, index) of item.list" :key="index">
+ <div class="relative mb-2">
+ <div
+ class="absolute inset-0 flex items-center"
+ aria-hidden="true"
+ >
+ <div class="w-full border-t border-gray-300"></div>
+ </div>
+ <div class="relative flex justify-start">
+ <router-link
+ :to="`/instance/${instanceSlug}/ds/${dataSourceSlug(
+ ds
+ )}`"
+ class="pr-3 bg-white font-medium normal-link"
+ >
+ {{ ds.name }}
+ </router-link>
+ </div>
+ </div>
+ <DataSourceConnectionPanel :dataSource="ds" />
+ </div>
+ </div>
+ </div>
+ </template>
</div>
</div>
</main>
@@ -105,6 +145,7 @@ import { computed, reactive } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import DataSourceTable from "../components/DataSourceTable.vue";
+import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";
import PrincipalSelect from "../components/PrincipalSelect.vue";
import { idFromSlug } from "../utils";
import { PrincipalId, DataSource } from "../types";
@@ -127,7 +168,7 @@ export default {
type: String,
},
},
- components: { DataSourceTable, PrincipalSelect },
+ components: { DataSourceConnectionPanel, DataSourceTable, PrincipalSelect },
setup(props, ctx) {
const store = useStore();
const router = useRouter();
@@ -152,6 +193,26 @@ export default {
);
});
+ const dataSourceList = computed(() => {
+ return store.getters["dataSource/dataSourceListByInstanceId"](
+ instance.value.id
+ ).filter((dataSource: DataSource) => {
+ return dataSource.databaseId == database.value.id;
+ });
+ });
+
+ const readWriteDataSourceList = computed(() => {
+ return dataSourceList.value.filter((dataSource: DataSource) => {
+ return dataSource.type == "RW";
+ });
+ });
+
+ const readOnlyDataSourceList = computed(() => {
+ return dataSourceList.value.filter((dataSource: DataSource) => {
+ return dataSource.type == "RO";
+ });
+ });
+
const isOwner = computed(() => {
return (
currentUser.value.id == database.value.ownerId ||
@@ -178,6 +239,8 @@ export default {
database,
instance,
isOwner,
+ readWriteDataSourceList,
+ readOnlyDataSourceList,
updateDatabaseOwner,
};
},