Skip to content

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

chore: add change type to apply changelist to database drawer (#13647)

boojack0052595a8a79
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue b/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue
index b5597ee6d5..2cf8d80b6c 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue
@@ -1,6 +1,6 @@
<template>
<div v-if="databaseList.length > 0" class="mt-4">
- <div class="px-0.5">
+ <div class="px-0.5 mb-2">
<NCheckbox v-model:checked="expand">
{{ $t("database.show-schemaless-databases") }}
</NCheckbox>
diff --git a/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vue b/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vue
index 3af2de9186..f1966cd26d 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vue
+++ b/frontend/src/components/Changelist/ChangelistDetail/ApplyToDatabasePanel/ApplyToDatabasePanel.vue
@@ -5,30 +5,28 @@
<div
class="w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)] overflow-x-auto"
>
- <div v-if="ready" class="flex flex-col gap-y-4">
- <ProjectStandardView
- :project="project"
+ <div v-if="ready" class="flex flex-col">
+ <div class="mb-4 flex flex-row justify-start items-center gap-2">
+ <span class="textlabel">{{ t("changelist.change-type") }}:</span>
+ <NRadioGroup v-model:value="state.changeType">
+ <NRadio :value="'DDL'" :label="t('issue.title.edit-schema')" />
+ <NRadio :value="'DML'" :label="t('issue.title.change-data')" />
+ </NRadioGroup>
+ </div>
+ <DatabaseV1Table
+ mode="PROJECT"
:database-list="schemaDatabaseList"
- :environment-list="environmentList"
- @select-databases="
- (...dbNameList) =>
- (state.selectedDatabaseNameList = new Set(dbNameList))
+ :show-selection="true"
+ :selected-database-names="state.selectedDatabaseNameList"
+ @update:selected-databases="
+ state.selectedDatabaseNameList = Array.from($event)
"
- >
- <template #header>
- <div class="flex items-center justify-end mx-2">
- <SearchBox
- v-model:value="state.keyword"
- class="m-px"
- :placeholder="$t('database.filter-database')"
- />
- </div>
- </template>
- </ProjectStandardView>
+ />
<SchemalessDatabaseTable
- v-if="guessedDatabaseChangeType === 'DDL'"
+ v-if="
+ state.changeType === 'DDL' && schemalessDatabaseList.length > 0
+ "
mode="PROJECT"
- class="px-2"
:database-list="schemalessDatabaseList"
/>
</div>
@@ -81,39 +79,33 @@
<script lang="ts" setup>
import { NButton } from "naive-ui";
+import { NRadioGroup, NRadio } from "naive-ui";
import { zindexable as vZindexable } from "vdirs";
import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBSpin } from "@/bbkit";
-import ProjectStandardView from "@/components/AlterSchemaPrepForm/ProjectStandardView.vue";
import SchemalessDatabaseTable from "@/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue";
-import {
- Drawer,
- DrawerContent,
- ErrorTipsButton,
- SearchBox,
-} from "@/components/v2";
+import { Drawer, DrawerContent, ErrorTipsButton } from "@/components/v2";
+import DatabaseV1Table from "@/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
-import { useDatabaseV1Store, useEnvironmentV1List } from "@/store";
+import { useDatabaseV1Store } from "@/store";
import { useDatabaseV1List } from "@/store/modules/v1/databaseList";
import type { ComposedDatabase } from "@/types";
import { DEFAULT_PROJECT_NAME } from "@/types";
import { State } from "@/types/proto/v1/common";
import {
extractProjectResourceName,
- filterDatabaseV1ByKeyword,
generateIssueTitle,
- guessChangelistChangeType,
instanceV1HasAlterSchema,
sortDatabaseV1List,
} from "@/utils";
import { useChangelistDetailContext } from "../context";
type LocalState = {
- keyword: string;
+ selectedDatabaseNameList: string[];
+ changeType: "DDL" | "DML";
isGenerating: boolean;
- selectedDatabaseNameList: Set<string>;
};
const { t } = useI18n();
@@ -126,28 +118,13 @@ const {
} = useChangelistDetailContext();
const state = reactive<LocalState>({
- selectedDatabaseNameList: new Set<string>(),
- keyword: "",
+ selectedDatabaseNameList: [],
+ changeType: "DDL",
isGenerating: false,
});
const { ready } = useDatabaseV1List(project.value.name);
-const environmentList = useEnvironmentV1List(false /* !showDeleted */);
-
-const guessedDatabaseChangeType = computed(() => {
- if (
- changelist.value.changes.every(
- (change) => guessChangelistChangeType(change) === "DML"
- )
- ) {
- // When ALL of the changes are DML, we are confident that the whole
- // changelist could be a DML
- return "DML";
- }
- return "DDL";
-});
-
const databaseList = computed(() => {
let list: ComposedDatabase[] = [];
list = databaseStore.databaseListByProject(project.value.name);
@@ -156,24 +133,15 @@ const databaseList = computed(() => {
(db) => db.syncState == State.ACTIVE && db.project !== DEFAULT_PROJECT_NAME
);
- list = list.filter((db) => {
- return filterDatabaseV1ByKeyword(db, state.keyword.trim(), [
- "name",
- "environment",
- "instance",
- ]);
- });
-
return sortDatabaseV1List(list);
});
const schemaDatabaseList = computed(() => {
- if (guessedDatabaseChangeType.value === "DDL") {
+ if (state.changeType === "DDL") {
return databaseList.value.filter((db) =>
instanceV1HasAlterSchema(db.instanceResource)
);
}
-
return databaseList.value;
});
@@ -205,7 +173,7 @@ const handleClickNext = async () => {
const query: Record<string, any> = {
template:
- guessedDatabaseChangeType.value === "DDL"
+ state.changeType === "DDL"
? "bb.issue.database.schema.update"
: "bb.issue.database.data.update",
name: generateIssueTitle(
@@ -231,8 +199,7 @@ const handleClickNext = async () => {
};
const reset = () => {
- state.selectedDatabaseNameList = new Set();
- state.keyword = "";
+ state.selectedDatabaseNameList = [];
};
watch(
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index eb5998528b..6d31cc4925 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3609,7 +3609,8 @@
"no-file-to-upload": "No file to upload",
"upload-sql-or-zip-file": "Upload .sql or .zip file",
"optional-upload-sql-or-zip-file": "(Optional) Upload .sql or .zip file"
- }
+ },
+ "change-type": "Change type"
},
"export-data": {
"export-rows": "Export rows",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 1daa01c055..75d2216505 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3609,7 +3609,8 @@
"no-file-to-upload": "No hay archivos para subir",
"upload-sql-or-zip-file": "Cargue el archivo .sql o .zip",
"optional-upload-sql-or-zip-file": "(Opcional) Cargue el archivo .sql o .zip"
- }
+ },
+ "change-type": "Cambiar tipo"
},
"export-data": {
"export-rows": "Exportar filas",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 239ff56700..b170d88955 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -3609,7 +3609,8 @@
"no-file-to-upload": "アップロードするファイルがありません",
"upload-sql-or-zip-file": ".sql または .zip ファイルをアップロードする",
"optional-upload-sql-or-zip-file": "(オプション) .sql または .zip ファイルをアップロードします"
- }
+ },
+ "change-type": "タイプを変更"
},
"export-data": {
"export-rows": "エクスポート行数",
diff --git a/frontend/src/locales/sql-review/es-ES.json b/frontend/src/locales/sql-review/es-ES.json
index fdc7624cfc..ccde323f9d 100644
--- a/frontend/src/locales/sql-review/es-ES.json
+++ b/frontend/src/locales/sql-review/es-ES.json
@@ -675,4 +675,4 @@
"warning": "Advertencia",
"disabled": "Deshabilitado"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/sql-review/ja-JP.json b/frontend/src/locales/sql-review/ja-JP.json
index f399323fed..38acae323a 100644
--- a/frontend/src/locales/sql-review/ja-JP.json
+++ b/frontend/src/locales/sql-review/ja-JP.json
@@ -675,4 +675,4 @@
"warning": "警告",
"disabled": "無効化"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.json
index 9c7c5db49b..3501dbf3b1 100644
--- a/frontend/src/locales/sql-review/zh-CN.json
+++ b/frontend/src/locales/sql-review/zh-CN.json
@@ -675,4 +675,4 @@
"warning": "警告",
"disabled": "禁用"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 5a7423dd93..4c11ba8b71 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -3609,7 +3609,8 @@
"no-file-to-upload": "没有可以上传的文件",
"upload-sql-or-zip-file": "上传 .sql 或 .zip 文件",
"optional-upload-sql-or-zip-file": "(可选)上传 .sql 或 .zip 文件"
- }
+ },
+ "change-type": "更改类型"
},
"export-data": {
"export-rows": "导出行数",
diff --git a/frontend/src/utils/v1/changelist.ts b/frontend/src/utils/v1/changelist.ts
index f5da3fe4d7..90b0ba07b2 100644
--- a/frontend/src/utils/v1/changelist.ts
+++ b/frontend/src/utils/v1/changelist.ts
@@ -1,7 +1,6 @@
-import { useChangeHistoryStore, useSheetV1Store } from "@/store";
+import { useSheetV1Store } from "@/store";
import type { Changelist_Change_Source, ComposedDatabase } from "@/types";
import type { Changelist_Change as Change } from "@/types/proto/v1/changelist_service";
-import { getHistoryChangeType } from "./changeHistory";
import { getSheetStatement } from "./sheet";
export const extractChangelistResourceName = (name: string) => {
@@ -29,30 +28,6 @@ export const getChangelistChangeSourceType = (
}
};
-export const guessChangelistChangeType = (
- change: Change
-): "DML" | "DDL" | "-" => {
- const type = getChangelistChangeSourceType(change);
- if (type === "CHANGE_HISTORY") {
- const history = useChangeHistoryStore().getChangeHistoryByName(
- change.source
- );
- if (!history) {
- return "-";
- }
- return getHistoryChangeType(history.type);
- }
- if (type === "BRANCH") {
- return "DDL";
- }
- if (type === "RAW_SQL") {
- return "-";
- }
-
- console.error("Should never reach this line");
- return "-";
-};
-
export const generateSQLForChangeToDatabase = async (
change: Change,
database: ComposedDatabase