Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: upload file when creating changelist (#11918)
Liu Jif95efbc49b36
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue b/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vueindex 30c17cb87d..ebcee95565 100644--- a/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue+++ b/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue@@ -43,6 +43,40 @@/></div></div>+ <div class="contents file-upload">+ <div class="col-span-2 flex flex-col gap-1">+ <NUpload+ v-model:file-list="uploadFileList"+ abstract+ accept="application/x-zip,.zip,application/sql,.sql"+ :multiple="false"+ @change="uploadFileList = [$event.file]"+ >+ <NUploadTrigger #="{ handleClick }" abstract>+ <NButton+ icon+ style="--n-padding: 0 10px"+ class="self-start"+ :loading="isParsingUploadFile"+ @click="handleClick"+ >+ <template #icon>+ <UploadIcon class="w-4 h-4" />+ </template>+ {{ $t("changelist.import.optional-upload-sql-or-zip-file") }}+ </NButton>+ </NUploadTrigger>+ <div class="flex flex-col gap-1">+ <NUploadFileList />+ </div>+ </NUpload>+ <div class="flex flex-col gap-1 pl-7 text-xs">+ <div v-for="(file, i) in files" :key="`${file.name}-${i}`">+ {{ file.name }}+ </div>+ </div>+ </div>+ </div></div><div@@ -82,7 +116,16 @@<script setup lang="ts">import { asyncComputed } from "@vueuse/core";-import { NButton, NInput, NTooltip } from "naive-ui";+import { UploadIcon } from "lucide-vue-next";+import {+ NButton,+ NInput,+ NTooltip,+ NUpload,+ NUploadFileList,+ NUploadTrigger,+ type UploadFileInfo,+} from "naive-ui";import { Status } from "nice-grpc-common";import { zindexable as vZindexable } from "vdirs";import { ref, watch } from "vue";@@ -99,13 +142,19 @@ import {pushNotification,useChangelistStore,useProjectV1Store,+ useSheetV1Store,} from "@/store";import type { ResourceId, ValidatedMessage } from "@/types";import { UNKNOWN_ID } from "@/types";import type { ComposedProject } from "@/types";-import { Changelist } from "@/types/proto/v1/changelist_service";-import { extractChangelistResourceName } from "@/utils";+import {+ Changelist,+ Changelist_Change as Change,+} from "@/types/proto/v1/changelist_service";+import { Sheet } from "@/types/proto/v1/sheet_service";+import { extractChangelistResourceName, setSheetStatement } from "@/utils";import { getErrorCode } from "@/utils/grpcweb";+import { readUpload, type ParsedFile } from "../import";import { useChangelistDashboardContext } from "./context";const props = defineProps<{@@ -173,6 +222,42 @@ const validateResourceId = async (return [];};+const uploadFileList = ref<UploadFileInfo[]>([]);+const files = ref<ParsedFile[]>([]);+const isParsingUploadFile = ref(false);++watch(uploadFileList, async (fileList) => {+ const file = fileList[0];+ if (!file) {+ files.value = [];+ return;+ }+ const cleanup = () => {+ isParsingUploadFile.value = false;+ };++ try {+ files.value = [];+ isParsingUploadFile.value = true;+ files.value = await readUpload(file);++ if (files.value.length === 0) {+ pushNotification({+ module: "bytebase",+ style: "WARN",+ title: t("changelist.import.no-file-to-upload"),+ });+ return cleanup();+ }++ if (!title.value) {+ title.value = file.name;+ }+ } finally {+ cleanup();+ }+});+const doCreate = async () => {if (errors.value.length > 0) return;if (!resourceIdField.value) return;@@ -181,10 +266,31 @@ const doCreate = async () => {try {const project = useProjectV1Store().getProjectByUID(projectUID.value!);+ const createdSheets = await Promise.all(+ files.value.map(async (f) => {+ const { name, content } = f;+ const sheet = Sheet.fromPartial({+ title: name,+ });+ setSheetStatement(sheet, content);+ const created = await useSheetV1Store().createSheet(+ project.name,+ sheet+ );+ return created;+ })+ );+ const changes = createdSheets.map((sheet) =>+ Change.fromPartial({+ sheet: sheet.name,+ })+ );+const created = await useChangelistStore().createChangelist({parent: project.name,changelist: Changelist.fromPartial({description: title.value,+ changes,}),changelistId: resourceId.value,});@@ -217,3 +323,18 @@ watch(showCreatePanel, (show) => {}});</script>++<style scoped lang="postcss">+.file-upload :deep(.n-upload-file-list .n-upload-file .n-upload-file-info) {+ @apply items-center;+}+.file-upload+ :deep(+ .n-upload-file-list+ .n-upload-file+ .n-upload-file-info+ .n-upload-file-info__thumbnail+ ) {+ @apply flex items-center justify-center mr-0.5;+}+</style>diff --git a/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue b/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vueindex 6d5cb61108..a6b6f5d119 100644--- a/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue+++ b/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue@@ -58,7 +58,7 @@ const handleFileChange = async (options: { file: UploadFileInfo }) => {try {isUpdating.value = true;- const files = await readUpload(options);+ const files = await readUpload(options.file);if (files.length === 0) {pushNotification({diff --git a/frontend/src/components/Changelist/import.ts b/frontend/src/components/Changelist/import.tsindex a571a2c467..fc6f028faa 100644--- a/frontend/src/components/Changelist/import.ts+++ b/frontend/src/components/Changelist/import.ts@@ -43,8 +43,7 @@ const readFile = (file: File) => {return d.promise;};-export const readUpload = async (options: { file: UploadFileInfo }) => {- const fileInfo = options.file;+export const readUpload = async (fileInfo: UploadFileInfo) => {if (!fileInfo.file) {return [];}diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 11be7c9c5b..874ba39f9a 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -3389,7 +3389,8 @@"confirm-delete-changelist": "Delete this changelist?","import": {"no-file-to-upload": "No file to upload",- "upload-sql-or-zip-file": "Upload .sql or .zip file"+ "upload-sql-or-zip-file": "Upload .sql or .zip file",+ "optional-upload-sql-or-zip-file": "(Optional) Upload .sql or .zip file"}},"export-data": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 1f9cdc4216..7864f79dc9 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -3389,7 +3389,8 @@"confirm-delete-changelist": "¿Eliminar esta lista de cambios?","import": {"no-file-to-upload": "No hay archivos para subir",- "upload-sql-or-zip-file": "Cargue el archivo .sql o .zip"+ "upload-sql-or-zip-file": "Cargue el archivo .sql o .zip",+ "optional-upload-sql-or-zip-file": "(Opcional) Cargue el archivo .sql o .zip"}},"export-data": {@@ -3465,4 +3466,4 @@"drop-partition-with-subpartitions-confirm": "También eliminará todas sus subparticiones."}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 2a1f7461e4..9cf2476a41 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -3389,7 +3389,8 @@"confirm-delete-changelist": "変更リストを削除しますか?","import": {"no-file-to-upload": "アップロードするファイルがありません",- "upload-sql-or-zip-file": ".sql または .zip ファイルをアップロードする"+ "upload-sql-or-zip-file": ".sql または .zip ファイルをアップロードする",+ "optional-upload-sql-or-zip-file": "(オプション) .sql または .zip ファイルをアップロードします"}},"export-data": {@@ -3465,4 +3466,4 @@"drop-partition-with-subpartitions-confirm": "すべてのサブパーティションが同時に削除されます。"}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 26033a1dd2..0c773fc412 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -3389,7 +3389,8 @@"confirm-delete-changelist": "Xóa danh sách thay đổi này?","import": {"no-file-to-upload": "Không có tập tin để tải lên",- "upload-sql-or-zip-file": "Tải lên tệp .sql hoặc .zip"+ "upload-sql-or-zip-file": "Tải lên tệp .sql hoặc .zip",+ "optional-upload-sql-or-zip-file": "(Tùy chọn) Tải lên tệp .sql hoặc .zip"}},"export-data": {@@ -3465,4 +3466,4 @@"drop-partition-with-subpartitions-confirm": "Cũng sẽ bỏ tất cả các phân vùng của nó."}}-}\ No newline at end of file+}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex db9756156b..158922d118 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -3389,7 +3389,8 @@"confirm-delete-changelist": "删除变更列表?","import": {"no-file-to-upload": "没有可以上传的文件",- "upload-sql-or-zip-file": "上传 .sql 或 .zip 文件"+ "upload-sql-or-zip-file": "上传 .sql 或 .zip 文件",+ "optional-upload-sql-or-zip-file": "(可选)上传 .sql 或 .zip 文件"}},"export-data": {