Skip to content

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

feat: retire issue rollback feature (#628)

Liu Jic44c4dcbc2e8
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 6f22cd126a..5816c5c3a7 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -16,11 +16,9 @@
>
<IssueStatusTransitionButtonGroup
:create="create"
- :allow-rollback="allowRollback"
:issue="issue"
:issue-template="issueTemplate"
@create="doCreate"
- @rollback="doRollback"
@change-issue-status="changeIssueStatus"
@change-task-status="changeTaskStatus"
/>
@@ -132,15 +130,13 @@
<!--
For tenant deploy mode, we provide only one statement panel.
It's editable only when creating an issue.
- It will never show Rollback SQL.
It is not allowed to "Apply to other stages".
-->
<IssueTaskStatementPanel
- :sql-hint="sqlHint(false)"
+ :sql-hint="sqlHint()"
:statement="selectedStatement"
:create="create"
:allow-edit="create"
- :rollback="false"
:show-apply-statement="false"
@update-statement="updateStatement"
/>
@@ -153,11 +149,10 @@
list every IssueTaskStatementPanel for each stage and use v-if to show the active one.-->
<template v-if="create">
<IssueTaskStatementPanel
- :sql-hint="sqlHint(false)"
+ :sql-hint="sqlHint()"
:statement="selectedStatement"
:create="create"
:allow-edit="true"
- :rollback="false"
:show-apply-statement="showIssueTaskStatementApply"
@update-statement="updateStatement"
@apply-statement-to-other-stages="
@@ -172,11 +167,10 @@
>
<template v-if="selectedStage.id == stage.id">
<IssueTaskStatementPanel
- :sql-hint="sqlHint(false)"
+ :sql-hint="sqlHint()"
:statement="statement(stage)"
:create="create"
:allow-edit="allowEditStatement"
- :rollback="false"
:show-apply-statement="showIssueTaskStatementApply"
@update-statement="updateStatement"
/>
@@ -184,42 +178,7 @@
</template>
</template>
</section>
- <section
- v-if="showIssueTaskRollbackStatementPanel"
- class="border-b mb-4"
- >
- <template v-if="create">
- <IssueTaskStatementPanel
- :sql-hint="sqlHint(true)"
- :statement="selectedRollbackStatement"
- :create="create"
- :allow-edit="false"
- :rollback="true"
- :show-apply-statement="showIssueTaskStatementApply"
- @update-statement="updateRollbackStatement"
- @apply-statement-to-other-stages="
- applyRollbackStatementToOtherStages
- "
- />
- </template>
- <template
- v-for="(stage, index) in issue.pipeline.stageList"
- v-else
- :key="index"
- >
- <template v-if="selectedStage.id == stage.id">
- <IssueTaskStatementPanel
- :sql-hint="sqlHint(true)"
- :statement="rollbackStatement(stage)"
- :create="create"
- :allow-edit="false"
- :rollback="true"
- :show-apply-statement="showIssueTaskStatementApply"
- @update-statement="updateRollbackStatement"
- />
- </template>
- </template>
- </section>
+
<IssueDescriptionPanel
:issue="issue"
:create="create"
@@ -445,24 +404,6 @@ export default defineComponent({
}
};
- const updateRollbackStatement = (newStatement: string) => {
- const stage = selectedStage.value as StageCreate;
- stage.taskList[0].rollbackStatement = newStatement;
- };
-
- const applyRollbackStatementToOtherStages = (newStatement: string) => {
- for (const stage of (props.issue as IssueCreate).pipeline!.stageList) {
- for (const task of stage.taskList) {
- if (
- task.type == "bb.task.database.schema.update" ||
- task.type == "bb.task.database.data.update"
- ) {
- task.rollbackStatement = newStatement;
- }
- }
- }
- };
-
const updateDescription = (
newDescription: string,
postUpdated: (updatedIssue: Issue) => void
@@ -544,19 +485,6 @@ export default defineComponent({
});
};
- const doRollback = () => {
- router.push({
- name: "workspace.issue.detail",
- params: {
- issueSlug: "new",
- },
- query: {
- template: props.issue.type,
- rollbackIssue: (props.issue as Issue).id,
- },
- });
- };
-
const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {
const issueStatusPatch: IssueStatusPatch = {
status: newStatus,
@@ -775,24 +703,6 @@ export default defineComponent({
}
};
- const rollbackStatement = (stage: Stage): string => {
- const task = stage.taskList[0];
- switch (task.type) {
- case "bb.task.database.schema.update":
- return (
- (task.payload as TaskDatabaseSchemaUpdatePayload)
- .rollbackStatement || ""
- );
- case "bb.task.database.data.update":
- return (
- (task.payload as TaskDatabaseDataUpdatePayload).rollbackStatement ||
- ""
- );
- default:
- return "";
- }
- };
-
const isTenantDeployMode = computed((): boolean => {
if (
props.issue.type === "bb.issue.database.schema.update" &&
@@ -845,11 +755,6 @@ export default defineComponent({
}
});
- const selectedRollbackStatement = computed((): string => {
- const task = (selectedStage.value as StageCreate).taskList[0];
- return task.rollbackStatement;
- });
-
const selectedMigrateType = computed((): MigrationType => {
if (
!props.create &&
@@ -930,52 +835,6 @@ export default defineComponent({
}
});
- // For now, we only support rollback for schema update issue when all below conditions met:
- // 0. NOT tenant deploy mode
- // 1. Issue is in DONE or CANCELED state
- // 2. There is at least one completed schema update task and the task contains the rollback statement.
- const allowRollback = computed(() => {
- if (isTenantDeployMode.value) {
- return false;
- }
- if (!props.create) {
- if (
- props.issue.type == "bb.issue.database.schema.update" ||
- props.issue.type == "bb.issue.database.data.update"
- ) {
- if (
- (props.issue as Issue).status == "DONE" ||
- (props.issue as Issue).status == "CANCELED"
- ) {
- for (const stage of (props.issue as Issue).pipeline.stageList) {
- for (const task of stage.taskList) {
- if (task.status == "DONE") {
- if (
- task.type == "bb.task.database.schema.update" &&
- !isEmpty(
- (task.payload as TaskDatabaseSchemaUpdatePayload)
- .rollbackStatement
- )
- ) {
- return true;
- } else if (
- task.type == "bb.task.database.data.update" &&
- !isEmpty(
- (task.payload as TaskDatabaseDataUpdatePayload)
- .rollbackStatement
- )
- ) {
- return true;
- }
- }
- }
- }
- }
- }
- }
- return false;
- });
-
const showCancelBanner = computed(() => {
return !props.create && (props.issue as Issue).status == "CANCELED";
});
@@ -1011,19 +870,6 @@ export default defineComponent({
);
});
- const showIssueTaskRollbackStatementPanel = computed(() => {
- if (isTenantDeployMode.value) return false;
- if (project.value.workflowType == "UI") {
- if (
- props.issue.type == "bb.issue.database.schema.update" ||
- props.issue.type == "bb.issue.database.data.update"
- ) {
- return true;
- }
- }
- return false;
- });
-
const showIssueTaskStatementApply = computed(() => {
if (!props.create) {
return false;
@@ -1071,15 +917,11 @@ export default defineComponent({
return (selectedTask.value as Task).instance;
});
- const sqlHint = (isRollBack: boolean): string | undefined => {
- if (
- !isRollBack &&
- !props.create &&
- selectedMigrateType.value == "BASELINE"
- ) {
+ const sqlHint = (): string | undefined => {
+ if (!props.create && selectedMigrateType.value == "BASELINE") {
return `This is a baseline migration and bytebase won't apply the SQL to the database, it will only record a baseline history`;
}
- if (!isRollBack && instance.value.engine === "SNOWFLAKE") {
+ if (instance.value.engine === "SNOWFLAKE") {
return `Use <<schema>>.<<table>> to specify a Snowflake table`;
}
return undefined;
@@ -1113,14 +955,11 @@ export default defineComponent({
updateStatement,
updateEarliestAllowedTime,
applyStatementToOtherStages,
- updateRollbackStatement,
- applyRollbackStatementToOtherStages,
updateAssigneeId,
addSubscriberId,
removeSubscriberId,
updateCustomField,
doCreate,
- doRollback,
changeIssueStatus,
changeTaskStatus,
runTaskChecks,
@@ -1135,22 +974,18 @@ export default defineComponent({
selectTask,
selectTaskId,
statement,
- rollbackStatement,
selectedStatement,
- selectedRollbackStatement,
selectedMigrateType,
allowEditSidebar,
allowEditOutput,
allowEditNameAndDescription,
allowEditStatement,
- allowRollback,
showCancelBanner,
showSuccessBanner,
showPendingApproval,
showPipelineFlowBar,
showIssueOutputPanel,
showIssueTaskStatementPanel,
- showIssueTaskRollbackStatementPanel,
showIssueTaskStatementApply,
hasBackwardCompatibilityFeature,
supportBackwardCompatibilityFeature,
diff --git a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
index 4da3cd0e28..fa2947a878 100644
--- a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
@@ -72,11 +72,6 @@
{{ $t(transition.buttonName) }}
</button>
</template>
- <template v-if="allowRollback">
- <button type="button" class="btn-primary" @click.prevent="doRollback">
- {{ $t("common.rollback") }}
- </button>
- </template>
</div>
</template>
</template>
@@ -172,10 +167,6 @@ export default defineComponent({
required: true,
type: Boolean,
},
- allowRollback: {
- required: true,
- type: Boolean,
- },
issue: {
required: true,
type: Object as PropType<Issue | IssueCreate>,
@@ -185,7 +176,7 @@ export default defineComponent({
type: Object as PropType<IssueTemplate>,
},
},
- emits: ["create", "rollback", "change-issue-status", "change-task-status"],
+ emits: ["create", "change-issue-status", "change-task-status"],
setup(props, { emit }) {
const { t } = useI18n();
@@ -440,10 +431,6 @@ export default defineComponent({
emit("create");
};
- const doRollback = () => {
- emit("rollback");
- };
-
return {
menu,
updateStatusModalState,
@@ -457,7 +444,6 @@ export default defineComponent({
doIssueStatusTransition,
allowCreate,
doCreate,
- doRollback,
};
},
});
diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
index 02a73141e6..a3eb2f87d0 100644
--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue
+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
@@ -3,17 +3,11 @@
<div class="flex space-x-4">
<div
class="text-sm font-medium"
- :class="
- !rollback && isEmpty(state.editStatement)
- ? 'text-red-600'
- : 'text-control'
- "
+ :class="isEmpty(state.editStatement) ? 'text-red-600' : 'text-control'"
>
- {{ rollback ? $t("issue.rollback-sql") : $t("common.sql") }}
- <span v-if="create && !rollback" class="text-red-600">*</span>
- <span v-if="sqlHint && !rollback" class="text-accent">{{
- `(${sqlHint})`
- }}</span>
+ {{ $t("common.sql") }}
+ <span v-if="create" class="text-red-600">*</span>
+ <span v-if="sqlHint" class="text-accent">{{ `(${sqlHint})` }}</span>
</div>
<button
v-if="showApplyStatement"
@@ -38,7 +32,7 @@
<!-- Use h-5 to avoid flickering when show/hide icon -->
<heroicons-solid:pencil class="h-5 w-5" />
</button>
- <!-- mt-0.5 is to prevent jiggling betweening switching edit/none-edit -->
+ <!-- mt-0.5 is to prevent jiggling between switching edit/none-edit -->
<button
v-if="state.editing"
type="button"
@@ -65,11 +59,7 @@
v-model="state.editStatement"
class="whitespace-pre-wrap mt-2 w-full resize-none border-white focus:border-white outline-none"
:class="state.editing ? 'focus:ring-control focus-visible:ring-2' : ''"
- :placeholder="
- create && rollback
- ? $t('issue.optional-add-sql-statement')
- : $t('issue.add-sql-statement')
- "
+ :placeholder="$t('issue.add-sql-statement')"
@input="
(e) => {
sizeToFit(e.target as HTMLTextAreaElement);
@@ -91,12 +81,8 @@
<div v-if="state.editStatement" v-highlight class="whitespace-pre-wrap">
{{ state.editStatement }}
</div>
- <div v-else-if="state.create" class="ml-2 text-control-light">
- {{
- rollback
- ? $t("issue.add-rollback-sql-statement")
- : $t("issue.add-sql-statement")
- }}
+ <div v-else-if="create" class="ml-2 text-control-light">
+ {{ $t("issue.add-sql-statement") }}
</div>
<div v-else class="ml-2 text-control-light">None</div>
</div>
@@ -135,10 +121,6 @@ export default defineComponent({
required: true,
type: Boolean,
},
- rollback: {
- required: true,
- type: Boolean,
- },
showApplyStatement: {
required: true,
type: Boolean,
diff --git a/frontend/src/plugins/issue/DatabaseDataUpdateTemplate.ts b/frontend/src/plugins/issue/DatabaseDataUpdateTemplate.ts
index 73536c02d9..4665494c63 100644
--- a/frontend/src/plugins/issue/DatabaseDataUpdateTemplate.ts
+++ b/frontend/src/plugins/issue/DatabaseDataUpdateTemplate.ts
@@ -31,9 +31,7 @@ const template: IssueTemplate = {
instanceId: ctx.databaseList[i].instance.id,
databaseId: ctx.databaseList[i].id,
statement: ctx.statementList ? ctx.statementList[i] : "",
- rollbackStatement: ctx.rollbackStatementList
- ? ctx.rollbackStatementList[i]
- : "",
+ rollbackStatement: "",
migrationType: "MIGRATE",
earliestAllowedTs: 0,
},
diff --git a/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts b/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts
index 0cfea708ae..a944a1218b 100644
--- a/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts
+++ b/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts
@@ -31,9 +31,7 @@ const template: IssueTemplate = {
instanceId: ctx.databaseList[i].instance.id,
databaseId: ctx.databaseList[i].id,
statement: ctx.statementList ? ctx.statementList[i] : "",
- rollbackStatement: ctx.rollbackStatementList
- ? ctx.rollbackStatementList[i]
- : "",
+ rollbackStatement: "",
migrationType: "MIGRATE",
earliestAllowedTs: 0,
},
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 5dacf1750a..e864ef25dc 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -179,7 +179,7 @@ export default defineComponent({
databaseId: task.database?.id,
migrationType: payload.migrationType,
statement: payload.statement,
- rollbackStatement: payload.rollbackStatement,
+ rollbackStatement: "",
earliestAllowedTs: task.earliestAllowedTs,
};
}),
@@ -226,238 +226,69 @@ export default defineComponent({
}
var newIssue: IssueCreate;
- // Create rollback issue
- if (router.currentRoute.value.query.rollbackIssue) {
- const rollbackIssue: Issue = store.getters["issue/issueById"](
- parseInt(router.currentRoute.value.query.rollbackIssue as string)
- );
-
- let validState = false;
- let title = "";
-
- // We expect user to create rollback from the original issue, which should have already fetched
- // issue remotely. Otherwise, this will return UNKNOWN_ID
- if (rollbackIssue.id == UNKNOWN_ID) {
- title =
- "INVALID STATE, please create rollback from the original issue.";
- } else {
- if (
- rollbackIssue.type != "bb.issue.database.schema.update" &&
- rollbackIssue.type != "bb.issue.database.data.update"
- ) {
- title =
- "INVALID STATE, only support to rollback update schema or change data issue.";
- } else if (
- rollbackIssue.status != "DONE" &&
- rollbackIssue.status != "CANCELED"
- ) {
- title =
- "INVALID STATE, only support to rollback issue in closed state.";
- } else {
- for (const stage of rollbackIssue.pipeline.stageList) {
- for (const task of stage.taskList) {
- if (task.status == "DONE") {
- if (
- task.type == "bb.task.database.schema.update" &&
- !isEmpty(
- (task.payload as TaskDatabaseSchemaUpdatePayload)
- .rollbackStatement
- )
- ) {
- validState = true;
- break;
- } else if (
- task.type == "bb.task.database.data.update" &&
- !isEmpty(
- (task.payload as TaskDatabaseDataUpdatePayload)
- .rollbackStatement
- )
- ) {
- validState = true;
- break;
- }
- }
- }
-
- if (validState) {
- break;
- }
- }
-
- if (!validState) {
- title =
- "INVALID STATE, no applicable update schema task to rollback.";
- }
- }
- }
- if (validState) {
- let environmentList: Environment[] = [];
- const approvalPolicyList: Policy[] = [];
- const databaseList: Database[] = [];
- const statementList: string[] = [];
- const rollbackStatementList: string[] = [];
- for (
- let i = rollbackIssue.pipeline.stageList.length - 1;
- i >= 0;
- i--
- ) {
- const stage = rollbackIssue.pipeline.stageList[i];
- for (let j = stage.taskList.length - 1; j >= 0; j--) {
- const task = stage.taskList[j];
- let allowRollback = false;
-
- if (task.status == "DONE") {
- if (
- task.type == "bb.task.database.schema.update" &&
- !isEmpty(
- (task.payload as TaskDatabaseSchemaUpdatePayload)
- .rollbackStatement
- )
- ) {
- allowRollback = true;
- } else if (
- task.type == "bb.task.database.data.update" &&
- !isEmpty(
- (task.payload as TaskDatabaseDataUpdatePayload)
- .rollbackStatement
- )
- ) {
- allowRollback = true;
- }
- }
-
- if (allowRollback) {
- environmentList.push(stage.environment);
- approvalPolicyList.push(
- store.getters["policy/policyByEnvironmentIdAndType"](
- stage.environment.id,
- "bb.policy.pipeline-approval"
- )
- );
- databaseList.push(task.database!);
- statementList.push(
- (task.payload as TaskDatabaseSchemaUpdatePayload)
- .rollbackStatement
- );
- rollbackStatementList.push(
- (task.payload as TaskDatabaseSchemaUpdatePayload).statement
- );
- }
- }
- }
+ // Create issue from normal query parameter
+ const databaseList: Database[] = [];
+ if (router.currentRoute.value.query.databaseList) {
+ for (const databaseId of (
+ router.currentRoute.value.query.databaseList as string
+ ).split(","))
+ databaseList.push(store.getters["database/databaseById"](databaseId));
+ }
- if (environmentList.length == 0) {
- newIssue = {
- ...defaultTemplate().buildIssue({
- environmentList: [],
- approvalPolicyList: [],
- databaseList: [],
- currentUser: currentUser.value,
- }),
- name: "INVALID STATE, no applicable update schema task to rollback.",
- projectId: UNKNOWN_ID,
- };
- } else {
- newIssue = {
- ...newIssueTemplate.value.buildIssue({
- environmentList,
- approvalPolicyList,
- databaseList,
- statementList,
- rollbackStatementList,
- currentUser: currentUser.value,
- }),
- projectId: rollbackIssue.project.id,
- name: `[Rollback] issue/${rollbackIssue.id} - ${rollbackIssue.name}`,
- description: rollbackIssue.description
- ? `====Original issue description BEGIN====\n\n${rollbackIssue.description}\n\n====Original issue description END====\n\n`
- : "",
- assigneeId: rollbackIssue.assignee.id,
- };
- }
- } else {
- newIssue = {
- ...defaultTemplate().buildIssue({
- environmentList: [],
- approvalPolicyList: [],
- databaseList: [],
- currentUser: currentUser.value,
- }),
- name: title,
- projectId: UNKNOWN_ID,
- };
+ const environmentList: Environment[] = [];
+ const approvalPolicyList: Policy[] = [];
+ if (router.currentRoute.value.query.environment) {
+ environmentList.push(
+ store.getters["environment/environmentById"](
+ router.currentRoute.value.query.environment
+ )
+ );
+ } else if (databaseList.length > 0) {
+ for (const database of databaseList) {
+ environmentList.push(database.instance.environment);
}
- newIssue.rollbackIssueId = rollbackIssue.id;
+ } else {
+ environmentList.push(...store.getters["environment/environmentList"]());
}
- // Create issue from normal query parameter
- else {
- const databaseList: Database[] = [];
- if (router.currentRoute.value.query.databaseList) {
- for (const databaseId of (
- router.currentRoute.value.query.databaseList as string
- ).split(","))
- databaseList.push(
- store.getters["database/databaseById"](databaseId)
- );
- }
- const environmentList: Environment[] = [];
- const approvalPolicyList: Policy[] = [];
- if (router.currentRoute.value.query.environment) {
- environmentList.push(
- store.getters["environment/environmentById"](
- router.currentRoute.value.query.environment
- )
- );
- } else if (databaseList.length > 0) {
- for (const database of databaseList) {
- environmentList.push(database.instance.environment);
- }
- } else {
- environmentList.push(
- ...store.getters["environment/environmentList"]()
- );
- }
+ for (const environment of environmentList) {
+ approvalPolicyList.push(
+ store.getters["policy/policyByEnvironmentIdAndType"](
+ environment.id,
+ "bb.policy.pipeline-approval"
+ )
+ );
+ }
- for (const environment of environmentList) {
- approvalPolicyList.push(
- store.getters["policy/policyByEnvironmentIdAndType"](
- environment.id,
- "bb.policy.pipeline-approval"
- )
- );
- }
+ newIssue = {
+ ...newIssueTemplate.value.buildIssue({
+ environmentList,
+ approvalPolicyList,
+ databaseList,
+ currentUser: currentUser.value,
+ }),
+ projectId: router.currentRoute.value.query.project
+ ? parseInt(router.currentRoute.value.query.project as string)
+ : UNKNOWN_ID,
+ };
- newIssue = {
- ...newIssueTemplate.value.buildIssue({
- environmentList,
- approvalPolicyList,
- databaseList,
- currentUser: currentUser.value,
- }),
- projectId: router.currentRoute.value.query.project
- ? parseInt(router.currentRoute.value.query.project as string)
- : UNKNOWN_ID,
- };
-
- // For demo mode, we assign the issue to the current user, so it can also experience the assignee user flow.
- if (store.getters["actuator/isDemo"]()) {
- newIssue.assigneeId = currentUser.value.id;
- }
+ // For demo mode, we assign the issue to the current user, so it can also experience the assignee user flow.
+ if (store.getters["actuator/isDemo"]()) {
+ newIssue.assigneeId = currentUser.value.id;
+ }
- if (router.currentRoute.value.query.name) {
- newIssue.name = router.currentRoute.value.query.name as string;
- }
- if (router.currentRoute.value.query.description) {
- newIssue.description = router.currentRoute.value.query
- .description as string;
- }
- if (router.currentRoute.value.query.assignee) {
- newIssue.assigneeId = parseInt(
- router.currentRoute.value.query.assignee as string
- );
- }
+ if (router.currentRoute.value.query.name) {
+ newIssue.name = router.currentRoute.value.query.name as string;
+ }
+ if (router.currentRoute.value.query.description) {
+ newIssue.description = router.currentRoute.value.query
+ .description as string;
+ }
+ if (router.currentRoute.value.query.assignee) {
+ newIssue.assigneeId = parseInt(
+ router.currentRoute.value.query.assignee as string
+ );
}
for (const field of newIssueTemplate.value.inputFieldList) {
const value = router.currentRoute.value.query[field.slug] as string;