Skip to content

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

feat: apply statement change to all pending tasks (#5717)

Liu Ji6ca3abc3b3bf
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 6d4cf7b6d0..82a976320f 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -97,6 +97,8 @@
import { computed, onMounted, PropType, ref, watch, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router";
+import { useDialog } from "naive-ui";
+
import {
pipelineType,
PipelineType,
@@ -163,6 +165,8 @@ const projectStore = useProjectStore();
const create = computed(() => props.create);
const issue = computed(() => props.issue);
+const dialog = useDialog();
+
const {
project,
isTenantMode,
@@ -387,6 +391,7 @@ provideIssueLogic(
selectedStatement,
allowApplyTaskStateToOthers,
applyTaskStateToOthers,
+ dialog,
},
true
// This is the root logic, could be overwritten by other (standard, gh-ost, tenant...) logic providers.
diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
index cfa0a30d5a..0c1537524c 100644
--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue
+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
@@ -31,7 +31,7 @@
}}</span>
</div>
<button
- v-if="allowApplyTaskStateToOthers"
+ v-if="create && allowApplyTaskStateToOthers"
:disabled="isEmpty(state.editStatement)"
type="button"
class="btn-small py-1 px-3 my-auto"
@@ -56,7 +56,10 @@
<span class="textlabel">{{ $t("issue.format-on-save") }}</span>
</label>
- <UploadProgressButton :upload="handleUploadFile">
+ <UploadProgressButton
+ v-if="allowUploadSheetForTask"
+ :upload="handleUploadFile"
+ >
{{ $t("issue.upload-sql") }}
</UploadProgressButton>
</template>
diff --git a/frontend/src/components/Issue/logic/GhostModeProvider.ts b/frontend/src/components/Issue/logic/GhostModeProvider.ts
index 480e69943f..582eb483c0 100644
--- a/frontend/src/components/Issue/logic/GhostModeProvider.ts
+++ b/frontend/src/components/Issue/logic/GhostModeProvider.ts
@@ -3,6 +3,7 @@ import { cloneDeep, isUndefined } from "lodash-es";
import { provideIssueLogic, useIssueLogic } from "./index";
import {
flattenTaskList,
+ getPatchingTaskList,
maybeFormatStatementOnSave,
TaskTypeWithSheetId,
TaskTypeWithStatement,
@@ -35,6 +36,7 @@ export default defineComponent({
allowApplyTaskStateToOthers: baseAllowApplyTaskStateToOthers,
applyTaskStateToOthers: baseApplyTaskStateToOthers,
onStatusChanged,
+ dialog,
} = useIssueLogic();
const databaseStore = useDatabaseStore();
const taskStore = useTaskStore();
@@ -114,6 +116,7 @@ export default defineComponent({
(detail) => (detail.statement = newStatement)
);
} else {
+ // Call patchAllTasksInIssue for tenant mode
const issueEntity = issue.value as Issue;
taskStore
.patchAllTasksInIssue({
@@ -135,18 +138,26 @@ export default defineComponent({
const task = selectedTask.value as TaskCreate;
task.statement = newStatement;
} else {
- // otherwise, patch the task
+ // Ask whether to apply the change to all pending tasks if possible.
const task = selectedTask.value as Task;
- patchTask(
- task.id,
- {
- statement: maybeFormatStatementOnSave(
- newStatement,
- task.database
- ),
- updatedTs: task.updatedTs,
- },
- postUpdated
+ getPatchingTaskList(issue.value as Issue, task, dialog).then(
+ (patchingTaskList) => {
+ if (patchingTaskList.length === 0) return;
+ const patchRequestList = patchingTaskList.map((task) => {
+ patchTask(
+ task.id,
+ {
+ statement: maybeFormatStatementOnSave(
+ newStatement,
+ task.database
+ ),
+ updatedTs: task.updatedTs,
+ },
+ postUpdated
+ );
+ });
+ return Promise.allSettled(patchRequestList);
+ }
);
}
}
diff --git a/frontend/src/components/Issue/logic/IssueLogic.ts b/frontend/src/components/Issue/logic/IssueLogic.ts
index 9616069152..0b6fa11d4a 100644
--- a/frontend/src/components/Issue/logic/IssueLogic.ts
+++ b/frontend/src/components/Issue/logic/IssueLogic.ts
@@ -1,4 +1,5 @@
-import { Ref } from "vue";
+import type { Ref } from "vue";
+import { type useDialog } from "naive-ui";
import { IssueTemplate } from "@/plugins";
import {
Database,
@@ -78,6 +79,9 @@ type IssueLogic = {
// status transition
allowApplyIssueStatusTransition(issue: Issue, to: IssueStatus): boolean;
allowApplyTaskStatusTransition(task: Task, to: TaskStatus): boolean;
+
+ // misc
+ dialog: ReturnType<typeof useDialog>;
};
export default IssueLogic;
diff --git a/frontend/src/components/Issue/logic/TenantModeProvider.ts b/frontend/src/components/Issue/logic/TenantModeProvider.ts
index 8679f9bc61..9d1aa4e953 100644
--- a/frontend/src/components/Issue/logic/TenantModeProvider.ts
+++ b/frontend/src/components/Issue/logic/TenantModeProvider.ts
@@ -66,6 +66,7 @@ export default defineComponent({
(detail) => (detail.statement = newStatement)
);
} else {
+ // Call patchAllTasksInIssue for tenant mode
const issueEntity = issue.value as Issue;
taskStore
.patchAllTasksInIssue({
diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.ts
index a4be48c45a..b247a887b8 100644
--- a/frontend/src/components/Issue/logic/common.ts
+++ b/frontend/src/components/Issue/logic/common.ts
@@ -34,12 +34,18 @@ import {
dialectOfEngine,
languageOfEngine,
} from "@/types";
-import { useIssueLogic } from "./index";
-import { isDev, isTaskTriggeredByVCS, taskCheckRunSummary } from "@/utils";
+import { IssueLogic, useIssueLogic } from "./index";
+import {
+ defer,
+ isDev,
+ isTaskTriggeredByVCS,
+ taskCheckRunSummary,
+} from "@/utils";
import { maybeApplyRollbackParams } from "@/plugins/issue/logic/initialize/standard";
+import { t } from "@/plugins/i18n";
export const useCommonLogic = () => {
- const { create, issue, selectedTask, createIssue, onStatusChanged } =
+ const { create, issue, selectedTask, createIssue, onStatusChanged, dialog } =
useIssueLogic();
const route = useRoute();
const currentUser = useCurrentUser();
@@ -171,21 +177,33 @@ export const useCommonLogic = () => {
const task = selectedTask.value as TaskCreate;
task.statement = newStatement;
} else {
- // otherwise, patch the task
+ // Ask whether to apply the change to all pending tasks if possible.
const task = selectedTask.value as Task;
- patchTask(
- task.id,
- {
- statement: maybeFormatStatementOnSave(newStatement, task.database),
- updatedTs: task.updatedTs,
- },
- postUpdated
+ getPatchingTaskList(issue.value as Issue, task, dialog).then(
+ (patchingTaskList) => {
+ if (patchingTaskList.length === 0) return;
+ const patchRequestList = patchingTaskList.map((task) => {
+ patchTask(
+ task.id,
+ {
+ statement: maybeFormatStatementOnSave(
+ newStatement,
+ task.database
+ ),
+ updatedTs: task.updatedTs,
+ },
+ postUpdated
+ );
+ });
+ return Promise.allSettled(patchRequestList);
+ }
);
}
};
const updateSheetId = (sheetId: SheetId | undefined) => {
if (!create.value) {
+ console.log("sheet id");
return;
}
@@ -369,3 +387,36 @@ export const isTaskEditable = (task: Task): boolean => {
return false;
};
+
+export const getPatchingTaskList = async (
+ issue: Issue,
+ task: Task,
+ dialog: IssueLogic["dialog"]
+) => {
+ const patchableTaskList = flattenTaskList<Task>(issue).filter(
+ (task) => TaskTypeWithStatement.includes(task.type) && isTaskEditable(task)
+ );
+ const d = defer<Task[]>();
+ if (patchableTaskList.length > 1) {
+ dialog.info({
+ title: t("task.apply-change-to-all-pending-tasks.title"),
+ style: "width: auto",
+ negativeText: t("task.apply-change-to-all-pending-tasks.current-only"),
+ positiveText: t("task.apply-change-to-all-pending-tasks.self"),
+ onPositiveClick: () => {
+ d.resolve(patchableTaskList);
+ },
+ onNegativeClick: () => {
+ d.resolve([task]);
+ },
+ autoFocus: false,
+ maskClosable: false,
+ closeOnEsc: false,
+ onClose: () => {
+ d.resolve([]);
+ },
+ });
+ }
+
+ return d.promise;
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 9ac7d2298c..3dc781052c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -329,7 +329,12 @@
"cancel-generating": "Cancel generating the SQL rollback",
"sql-rollback-tips": "When enabled, Bytebase will keep the rollback logs for the data change\nand allow you to create a new issue to revert this change.\nWarning: If the table does not have a primary key. Undo SQL may affect\nduplicate rows. Please carefully confirm before executing.\n{link}"
},
- "skip-failed-in-current-stage": "Skip failed tasks in current stage"
+ "skip-failed-in-current-stage": "Skip failed tasks in current stage",
+ "apply-change-to-all-pending-tasks": {
+ "title": "Apply change to all pending tasks?",
+ "self": "Apply change to all pending tasks",
+ "current-only": "Only apply change to current task"
+ }
},
"banner": {
"update-license": "Update license",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 91ff06034c..36df2ae7bf 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -327,7 +327,12 @@
"cancel-generating": "取消生成回滚语句",
"sql-rollback-tips": "开启时,Bytebase 会保留数据变更的回滚日志,\n可以用于创建一个新的工单来回滚这次变更。\n警告:如果你的数据表没有主键,回滚语句可能\n会影响重复的行。执行前请注意确认。\n{link}"
},
- "skip-failed-in-current-stage": "跳过当前阶段失败的任务"
+ "skip-failed-in-current-stage": "跳过当前阶段失败的任务",
+ "apply-change-to-all-pending-tasks": {
+ "title": "应用到所有未执行任务?",
+ "self": "应用到所有未执行任务",
+ "current-only": "只应用到当前任务"
+ }
},
"banner": {
"update-license": "更新证书",