Skip to content

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

Make UI appear the database has only single data source

天舟62fe03ce560f
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index e35cb8a780..68ea99635b 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -18,7 +18,7 @@ import {
Environment,
EnvironmentId,
} from "../types";
-import { databaseSlug, allowDatabaseAccess, environmentName } from "../utils";
+import { databaseSlug, environmentName } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
interface LocalState {
@@ -63,17 +63,12 @@ export default {
}
for (const database of state.databaseList) {
if (database.name != ALL_DATABASE_NAME) {
- let databaseName = database.name;
- if (!allowDatabaseAccess(database, currentUser.value, "RW")) {
- databaseName += " (read)";
- }
-
const dbList = envToDbMap.get(database.instance.environment.id)!;
// dbList may be undefined if the environment is archived
if (dbList) {
dbList.push({
id: database.id,
- name: databaseName,
+ name: database.name,
link: `/db/${databaseSlug(database)}`,
});
}
diff --git a/frontend/src/miragejs/factories/dataSource.js b/frontend/src/miragejs/factories/dataSource.js
index 73875bbfcf..147df035e0 100644
--- a/frontend/src/miragejs/factories/dataSource.js
+++ b/frontend/src/miragejs/factories/dataSource.js
@@ -25,30 +25,8 @@ export default {
password(i) {
return "pwd" + i;
},
- afterCreate(dataSource, server) {},
- memberList(i) {
- const list = [
- {
- principalId: "1",
- taskId: (i + 1).toString(),
- createdTs: Date.now() - (i + 1) * 1800 * 1000,
- },
- ];
- if (i % 2 == 0) {
- list.push({
- principalId: "2",
- taskId: (i + 1).toString(),
- createdTs: Date.now() - (i + 1) * 1800 * 1000,
- });
- }
- if (i % 3 == 0 || i % 4 == 0) {
- list.push({
- principalId: "3",
- taskId: (i + 1).toString(),
- createdTs: Date.now() - (i + 1) * 1800 * 1000,
- });
- }
- return list;
+ memberList() {
+ return [];
},
}),
};
diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.js
index c5370bc659..f358ddea24 100644
--- a/frontend/src/miragejs/models/index.js
+++ b/frontend/src/miragejs/models/index.js
@@ -115,6 +115,8 @@ export default {
dataSourceMember: Model,
+ dataSourcePatch: Model,
+
batchUpdate: Model,
signupInfo: Model,
diff --git a/frontend/src/miragejs/routes/dataSource.js b/frontend/src/miragejs/routes/dataSource.js
index 836c23da09..032bc50d45 100644
--- a/frontend/src/miragejs/routes/dataSource.js
+++ b/frontend/src/miragejs/routes/dataSource.js
@@ -66,7 +66,31 @@ export default function configureDataSource(route) {
);
}
const attrs = this.normalizedRequestAttrs("data-source");
- return dataSource.update(attrs);
+
+ let hasChange = false;
+
+ if (attrs.name) {
+ if (attrs.name != dataSource.name) {
+ hasChange = true;
+ }
+ }
+
+ if (attrs.username) {
+ if (attrs.username != dataSource.username) {
+ hasChange = true;
+ }
+ }
+
+ if (attrs.password) {
+ if (attrs.password != dataSource.password) {
+ hasChange = true;
+ }
+ }
+
+ if (hasChange) {
+ return dataSource.update(attrs);
+ }
+ return dataSource;
}
return new Response(
404,
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index 6abd353c7d..1c7cb2c8f8 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -621,16 +621,6 @@ const createInstanceList = (
password: "pwdadminRW",
});
- server.create("dataSource", {
- workspaceId: instance.workspaceId,
- instance,
- database: allDatabase,
- name: instance.name + " admin RO",
- type: "RO",
- username: "adminRO",
- password: "pwdadminRO",
- });
-
for (let i = 0; i < 2; i++) {
const database = server.create("database", {
workspaceId: instance.workspaceId,
@@ -643,21 +633,11 @@ const createInstanceList = (
workspaceId: instance.workspaceId,
instance,
database,
- name: database.name + " RW",
+ name: database.name + " default RW",
type: "RW",
username: "rootRW",
password: "pwdRW",
});
-
- server.create("dataSource", {
- workspaceId: instance.workspaceId,
- instance,
- database,
- name: database.name + " RO",
- type: "RO",
- username: "rootRO",
- password: "pwdRO",
- });
}
}
diff --git a/frontend/src/store/modules/dataSource.ts b/frontend/src/store/modules/dataSource.ts
index dff2cb5196..7c95a4e98c 100644
--- a/frontend/src/store/modules/dataSource.ts
+++ b/frontend/src/store/modules/dataSource.ts
@@ -13,6 +13,7 @@ import {
unknown,
Database,
Instance,
+ DataSourcePatch,
} from "../../types";
function convert(
@@ -150,16 +151,23 @@ const actions = {
{ commit, dispatch, rootGetters }: any,
{
databaseId,
+ dataSourceId,
dataSource,
}: {
databaseId: DatabaseId;
- dataSource: DataSource;
+ dataSourceId: DataSourceId;
+ dataSource: DataSourcePatch;
}
) {
- const { id, ...attrs } = dataSource;
const data = (
- await axios.post(
- `/api/database/${databaseId}/datasource/${dataSource.id}?include=database,instance`
+ await axios.patch(
+ `/api/database/${databaseId}/datasource/${dataSourceId}?include=database,instance`,
+ {
+ data: {
+ type: "data-source-patch",
+ attributes: dataSource,
+ },
+ }
)
).data;
const updatedDataSource = convert(data.data, data.included, rootGetters);
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 9fd178b2b0..0a60c7a996 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -811,6 +811,12 @@ export type DataSourceNew = {
password?: string;
};
+export type DataSourcePatch = {
+ name?: string;
+ username?: string;
+ password?: string;
+};
+
export type DataSourceMember = {
principal: Principal;
taskId?: TaskId;
diff --git a/frontend/src/views/DataSourceDetail.vue b/frontend/src/views/DataSourceDetail.vue
index dddd622a4a..cc1e5a44ac 100644
--- a/frontend/src/views/DataSourceDetail.vue
+++ b/frontend/src/views/DataSourceDetail.vue
@@ -135,10 +135,11 @@
:dataSource="state.editing ? state.editingDataSource : dataSource"
/>
+ <!-- Hide member table for now as we currently don't support fine granualar access -->
<!-- Guard against dataSource.id != '-1', this could happen when we delete the data source -->
<DataSourceMemberTable
class="pt-6"
- v-if="dataSource.id != '-1'"
+ v-if="false && dataSource.id != '-1'"
:allowEdit="allowEdit"
:dataSource="dataSource"
/>
@@ -169,7 +170,7 @@ import isEqual from "lodash-es/isEqual";
import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";
import DataSourceMemberTable from "../components/DataSourceMemberTable.vue";
import { idFromSlug, isDBAOrOwner } from "../utils";
-import { DataSource, Principal } from "../types";
+import { DataSource, DataSourcePatch, Principal } from "../types";
interface LocalState {
editing: boolean;
@@ -241,10 +242,16 @@ export default {
};
const saveEdit = () => {
+ const dataSourcePatch: DataSourcePatch = {
+ name: state.editingDataSource?.name,
+ username: state.editingDataSource?.username,
+ password: state.editingDataSource?.password,
+ };
store
.dispatch("dataSource/patchDataSource", {
databaseId: dataSource.value.database.id,
- dataSource: state.editingDataSource,
+ dataSourceid: dataSource.value.id,
+ dataSource: dataSourcePatch,
})
.then(() => {
state.editingDataSource = undefined;
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index f7a1630052..e9a9aaafd2 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -117,9 +117,8 @@
</div>
<div class="space-y-4">
<div v-for="(ds, index) of item.list" :key="index">
- <!-- Only displays the data source link for DBA. Since for now
- we don't need to expose the data source concept to the end user -->
- <div v-if="isCurrentUserDBAOrOwner" class="relative mb-2">
+ <!-- Hide the data source detail link for now -->
+ <div v-if="false" class="relative mb-2">
<div
class="absolute inset-0 flex items-center"
aria-hidden="true"
@@ -137,7 +136,65 @@
</router-link>
</div>
</div>
- <DataSourceConnectionPanel :dataSource="ds" />
+ <div
+ v-if="allowChangeDataSource"
+ class="flex justify-end space-x-3"
+ >
+ <template v-if="isEditingDataSource(ds)">
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="cancelEditDataSource"
+ >
+ Cancel
+ </button>
+ <button
+ type="button"
+ class="btn-normal"
+ :disabled="!allowSaveDataSource"
+ @click.prevent="saveEditDataSource"
+ >
+ <!-- Heroicon name: solid/save -->
+ <svg
+ class="-ml-1 mr-2 h-5 w-5 text-control-light"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M7.707 10.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V6h5a2 2 0 012 2v7a2 2 0 01-2 2H4a2 2 0 01-2-2V8a2 2 0 012-2h5v5.586l-1.293-1.293zM9 4a1 1 0 012 0v2H9V4z"
+ ></path>
+ </svg>
+ <span>Save</span>
+ </button>
+ </template>
+ <template v-else>
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="editDataSource(ds)"
+ >
+ <!-- Heroicon name: solid/pencil -->
+ <svg
+ class="-ml-1 mr-2 h-5 w-5 text-control-light"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"
+ ></path>
+ </svg>
+ <span>Edit</span>
+ </button>
+ </template>
+ </div>
+ <DataSourceConnectionPanel
+ :editing="isEditingDataSource(ds)"
+ :dataSource="
+ isEditingDataSource(ds) ? state.editingDataSource : ds
+ "
+ />
</div>
</div>
</div>
@@ -157,11 +214,10 @@ import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.v
import PrincipalSelect from "../components/PrincipalSelect.vue";
import ProjectSelect from "../components/ProjectSelect.vue";
import { idFromSlug, isDBAOrOwner } from "../utils";
-import { PrincipalId, DataSource, ProjectId } from "../types";
+import { PrincipalId, DataSource, ProjectId, DataSourcePatch } from "../types";
+import { cloneDeep, isEqual } from "lodash";
interface LocalState {
- editing: boolean;
- showPassword: boolean;
editingDataSource?: DataSource;
}
@@ -183,10 +239,7 @@ export default {
const store = useStore();
const router = useRouter();
- const state = reactive<LocalState>({
- editing: false,
- showPassword: false,
- });
+ const state = reactive<LocalState>({});
const currentUser = computed(() => store.getters["auth/currentUser"]());
@@ -204,6 +257,10 @@ export default {
return isCurrentUserDBAOrOwner.value;
});
+ const allowChangeDataSource = computed(() => {
+ return isCurrentUserDBAOrOwner.value;
+ });
+
const dataSourceList = computed(() => {
return database.value.dataSourceList.filter((dataSource: DataSource) => {
return (
@@ -247,14 +304,62 @@ export default {
});
};
+ const isEditingDataSource = (dataSource: DataSource) => {
+ return (
+ state.editingDataSource && state.editingDataSource.id == dataSource.id
+ );
+ };
+
+ const allowSaveDataSource = computed(() => {
+ for (const dataSource of dataSourceList.value) {
+ if (dataSource.id == state.editingDataSource!.id) {
+ return !isEqual(dataSource, state.editingDataSource);
+ }
+ }
+ return false;
+ });
+
+ const editDataSource = (dataSource: DataSource) => {
+ state.editingDataSource = cloneDeep(dataSource);
+ };
+
+ const cancelEditDataSource = () => {
+ state.editingDataSource = undefined;
+ };
+
+ const saveEditDataSource = () => {
+ const dataSourcePatch: DataSourcePatch = {
+ username: state.editingDataSource?.username,
+ password: state.editingDataSource?.password,
+ };
+ store
+ .dispatch("dataSource/patchDataSource", {
+ databaseId: state.editingDataSource!.database.id,
+ dataSourceId: state.editingDataSource!.id,
+ dataSource: dataSourcePatch,
+ })
+ .then(() => {
+ state.editingDataSource = undefined;
+ })
+ .catch((error) => {
+ console.log(error);
+ });
+ };
+
return {
state,
database,
isCurrentUserDBAOrOwner,
allowChangeProject,
+ allowChangeDataSource,
readWriteDataSourceList,
readOnlyDataSourceList,
updateProject,
+ isEditingDataSource,
+ allowSaveDataSource,
+ editDataSource,
+ cancelEditDataSource,
+ saveEditDataSource,
};
},
};
diff --git a/frontend/src/views/DatabaseNew.vue b/frontend/src/views/DatabaseNew.vue
index d92cde19e2..c30a1f87ce 100644
--- a/frontend/src/views/DatabaseNew.vue
+++ b/frontend/src/views/DatabaseNew.vue
@@ -452,31 +452,10 @@ export default {
instanceId: state.instanceId!,
username: isEmpty(state.username) ? undefined : state.username,
password: isEmpty(state.passsword) ? undefined : state.passsword,
- memberList: [
- {
- principalId: currentUser.value.id,
- taskId: linkedTask?.id,
- },
- ],
+ memberList: [],
};
await store.dispatch("dataSource/createDataSource", newRwDataSource);
- const newRoDataSource: DataSourceNew = {
- name: "Default RO",
- type: "RO",
- databaseId: createdDatabase.id,
- instanceId: state.instanceId!,
- username: isEmpty(state.username) ? undefined : state.username,
- password: isEmpty(state.passsword) ? undefined : state.passsword,
- memberList: [
- {
- principalId: currentUser.value.id,
- taskId: linkedTask?.id,
- },
- ],
- };
- await store.dispatch("dataSource/createDataSource", newRoDataSource);
-
// Redirect to the created database.
router.push(`/db/${databaseSlug(createdDatabase)}`);
@@ -524,7 +503,7 @@ export default {
store.dispatch("notification/pushNotification", {
module: "bytebase",
style: "SUCCESS",
- title: `Succesfully created database '${createdDatabase.name}' and its Read & Write and Read Only data sources.`,
+ title: `Succesfully created database '${createdDatabase.name}'.`,
description: linkedTask
? `We also linked the created database to the requested task '${linkedTask.name}'.`
: "",