Skip to content

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

chore: implement update export config (#11512)

boojack4a73a9cf20bc
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 728a57e8d4..1aeac54205 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -1060,6 +1060,33 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePla
return nil, err
}
+ // ExportDataConfig
+ if err := func() error {
+ if task.Type != api.TaskDatabaseDataExport {
+ return nil
+ }
+ payload := &api.TaskDatabaseDataExportPayload{}
+ if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {
+ return status.Errorf(codes.Internal, "failed to unmarshal task payload: %v", err)
+ }
+ config, ok := spec.Config.(*v1pb.Plan_Spec_ExportDataConfig)
+ if !ok {
+ return nil
+ }
+ if config.ExportDataConfig.Format != convertExportFormat(payload.Format) {
+ format := convertToExportFormat(config.ExportDataConfig.Format)
+ taskPatch.ExportFormat = &format
+ doUpdate = true
+ }
+ if (config.ExportDataConfig.Password == nil && payload.Password != "") || (config.ExportDataConfig.Password != nil && *config.ExportDataConfig.Password != payload.Password) {
+ taskPatch.ExportPassword = config.ExportDataConfig.Password
+ doUpdate = true
+ }
+ return nil
+ }(); err != nil {
+ return nil, err
+ }
+
// version
if err := func() error {
switch task.Type {
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index c7bc1d5c67..8881cd3d04 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -268,6 +268,8 @@ type TaskPatch struct {
// When RollbackEnabled is enabled, RollbackSheetID is kept till it's set to the new sheet ID by the runner.
RollbackSheetID *int
RollbackError *string
+ ExportFormat *storepb.ExportFormat
+ ExportPassword *string
// Flags for gh-ost.
Flags *map[string]string
diff --git a/backend/store/task.go b/backend/store/task.go
index 529bb00d8e..fb1be086dd 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -314,6 +314,12 @@ func (s *Store) UpdateTaskV2(ctx context.Context, patch *api.TaskPatch) (*TaskMe
if v := patch.RollbackError; v != nil {
payloadSet, args = append(payloadSet, fmt.Sprintf(`jsonb_build_object('rollbackError', to_jsonb($%d::TEXT))`, len(args)+1)), append(args, *v)
}
+ if v := patch.ExportFormat; v != nil {
+ payloadSet, args = append(payloadSet, fmt.Sprintf(`jsonb_build_object('format', to_jsonb($%d::INT))`, len(args)+1)), append(args, *v)
+ }
+ if v := patch.ExportPassword; v != nil {
+ payloadSet, args = append(payloadSet, fmt.Sprintf(`jsonb_build_object('password', to_jsonb($%d::TEXT))`, len(args)+1)), append(args, *v)
+ }
if v := patch.Flags; v != nil {
jsonb, err := json.Marshal(v)
if err != nil {
diff --git a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportFormatSelector.vue b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportFormatSelector.vue
index 8bfe96b7e6..366a88258b 100644
--- a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportFormatSelector.vue
+++ b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportFormatSelector.vue
@@ -1,5 +1,5 @@
<template>
- <NRadioGroup v-if="isCreating" :value="format" @update:value="handleUpdate">
+ <NRadioGroup v-if="editable" :value="format" @update:value="handleUpdate">
<NRadio
v-for="formatItem in availableExportFormats"
:key="formatItem"
@@ -16,18 +16,17 @@
import { NRadioGroup, NRadio } from "naive-ui";
import { computed } from "vue";
import { onMounted } from "vue";
-import { useIssueContext } from "@/components/IssueV1";
import { ExportFormat, exportFormatToJSON } from "@/types/proto/v1/common";
const props = defineProps<{
format: ExportFormat;
+ editable?: boolean;
}>();
const emit = defineEmits<{
(event: "update:format", value: ExportFormat): void;
}>();
-const { isCreating } = useIssueContext();
const availableExportFormats = computed(() => [
ExportFormat.JSON,
ExportFormat.CSV,
diff --git a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
index e67bd3033a..4ff4fc6660 100644
--- a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
+++ b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
@@ -1,27 +1,74 @@
<template>
<div class="w-full flex flex-col">
- <div class="w-full flex flex-row items-center mb-1">
+ <div class="w-full flex flex-row justify-between items-center mb-1">
<span class="textlabel mr-4">{{ $t("issue.data-export.options") }}</span>
+ <div
+ v-if="!isCreating"
+ class="flex flex-row justify-end items-center gap-2"
+ >
+ <NTooltip
+ v-if="!state.isEditing"
+ :disabled="denyEditTaskReasons.length === 0"
+ >
+ <template #trigger>
+ <NButton
+ size="tiny"
+ tag="div"
+ :disabled="denyEditTaskReasons.length > 0"
+ @click="state.isEditing = true"
+ >
+ {{ $t("common.edit") }}
+ </NButton>
+ </template>
+ <template #default>
+ <ErrorList :errors="denyEditTaskReasons" />
+ </template>
+ </NTooltip>
+ <template v-else>
+ <NButton size="tiny" @click="handleSaveEdit">
+ {{ $t("common.save") }}
+ </NButton>
+ <NButton size="tiny" quaternary @click.prevent="handleCancelEdit">
+ {{ $t("common.cancel") }}
+ </NButton>
+ </template>
+ </div>
</div>
<div class="w-full h-8 flex flex-row justify-start items-center">
<span class="textinfolabel inline-block mr-2 !min-w-[64px]">{{
$t("issue.data-export.format")
}}</span>
- <ExportFormatSelector v-model:format="state.config.format" />
+ <ExportFormatSelector
+ :key="refreshKey"
+ v-model:format="state.config.format"
+ :editable="optionsEditable"
+ />
</div>
<div class="w-full h-8 flex flex-row justify-start items-center">
<span class="textinfolabel inline-block mr-2 !min-w-[64px]">{{
$t("issue.data-export.encrypt")
}}</span>
- <ExportPasswordInputer v-model:password="state.config.password" />
+ <ExportPasswordInputer
+ :key="refreshKey"
+ v-model:password="state.config.password"
+ :editable="optionsEditable"
+ />
</div>
</div>
</template>
<script lang="ts" setup>
-import { head } from "lodash-es";
-import { computed, watch, reactive } from "vue";
-import { useIssueContext } from "@/components/IssueV1/logic";
+import { cloneDeep, head } from "lodash-es";
+import { NButton, NTooltip } from "naive-ui";
+import { computed, watch, reactive, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import {
+ allowUserToEditStatementForTask,
+ notifyNotEditableLegacyIssue,
+ useIssueContext,
+} from "@/components/IssueV1/logic";
+import { rolloutServiceClient } from "@/grpcweb";
+import { pushNotification, useCurrentUserV1 } from "@/store";
import {
Plan_Spec,
Plan_ExportDataConfig,
@@ -31,9 +78,13 @@ import ExportPasswordInputer from "./ExportPasswordInputer.vue";
interface LocalState {
config: Plan_ExportDataConfig;
+ isEditing: boolean;
}
-const { issue } = useIssueContext();
+const { t } = useI18n();
+const { issue, isCreating, selectedTask, events } = useIssueContext();
+const currentUser = useCurrentUserV1();
+const refreshKey = ref(0);
const spec = computed(
() =>
@@ -42,12 +93,71 @@ const spec = computed(
);
const state = reactive<LocalState>({
- config: spec.value.exportDataConfig || Plan_ExportDataConfig.fromPartial({}),
+ config: Plan_ExportDataConfig.fromPartial({ ...spec.value.exportDataConfig }),
+ isEditing: false,
+});
+
+const denyEditTaskReasons = computed(() => {
+ return allowUserToEditStatementForTask(
+ issue.value,
+ selectedTask.value,
+ currentUser.value
+ );
+});
+
+const optionsEditable = computed(() => {
+ return isCreating.value || state.isEditing;
});
+const handleCancelEdit = () => {
+ state.isEditing = false;
+ state.config = Plan_ExportDataConfig.fromPartial({
+ ...spec.value.exportDataConfig,
+ });
+ // Trigger a re-render of the child components.
+ refreshKey.value++;
+};
+
+const handleSaveEdit = async () => {
+ const planPatch = cloneDeep(issue.value.planEntity);
+ if (!planPatch) {
+ notifyNotEditableLegacyIssue();
+ return;
+ }
+
+ const distinctSpecIds = new Set([spec.value.id]);
+ const specsToPatch = planPatch.steps
+ .flatMap((step) => step.specs)
+ .filter((spec) => distinctSpecIds.has(spec.id));
+ for (let i = 0; i < specsToPatch.length; i++) {
+ const spec = specsToPatch[i];
+ const config = spec.exportDataConfig;
+ if (!config) continue;
+ config.format = state.config.format;
+ config.password = state.config.password || undefined;
+ }
+
+ const updatedPlan = await rolloutServiceClient.updatePlan({
+ plan: planPatch,
+ updateMask: ["steps"],
+ });
+ issue.value.planEntity = updatedPlan;
+
+ events.emit("status-changed", { eager: true });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+ handleCancelEdit();
+};
+
watch(
() => state.config,
() => {
+ if (!isCreating.value) {
+ return;
+ }
spec.value.exportDataConfig = Plan_ExportDataConfig.fromPartial({
...spec.value.exportDataConfig,
format: state.config.format,
diff --git a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportPasswordInputer.vue b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportPasswordInputer.vue
index b7f45c36cc..6dde272e63 100644
--- a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportPasswordInputer.vue
+++ b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportPasswordInputer.vue
@@ -1,10 +1,10 @@
<template>
<NSwitch
v-model:value="state.encryptEnabled"
- :disabled="!isCreating"
+ :disabled="!editable"
size="small"
/>
- <tempalte v-if="isCreating && state.encryptEnabled">
+ <tempalte v-if="editable && state.encryptEnabled">
<span class="textinfolabel pl-4 pr-2"
>{{ $t("common.password") }}
<RequiredStar />
@@ -22,7 +22,6 @@
<script setup lang="ts">
import { NSwitch, NInput } from "naive-ui";
import { reactive, watch } from "vue";
-import { useIssueContext } from "@/components/IssueV1";
import RequiredStar from "@/components/RequiredStar.vue";
interface LocalState {
@@ -32,13 +31,13 @@ interface LocalState {
const props = defineProps<{
password?: string;
+ editable?: boolean;
}>();
const emit = defineEmits<{
(event: "update:password", value: string): void;
}>();
-const { isCreating } = useIssueContext();
const state = reactive<LocalState>({
encryptEnabled: Boolean(props.password),
password: props.password || "",
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index 3e57b6c89e..ece190b9cd 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -16,9 +16,6 @@
>
🎈{{ $t("sql-review.unlock-full-feature") }}
</NButton>
- <!-- <span v-if="sqlHint && !readonly" class="text-accent">{{
- `(${sqlHint})`
- }}</span> -->
</div>
<NButton