Skip to content

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

refactor: title/description of plan and issue (#16953)

boojack38993523e225
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 653195e5ba..f90ef47b01 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -376,16 +376,11 @@ func (s *IssueService) getUserByIdentifier(ctx context.Context, identifier strin
// CreateIssue creates a issue.
func (s *IssueService) CreateIssue(ctx context.Context, req *connect.Request[v1pb.CreateIssueRequest]) (*connect.Response[v1pb.Issue], error) {
- // Validate requests.
- if req.Msg.Issue.Title == "" {
- return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("issue title is required"))
- }
- if req.Msg.Issue.Type == v1pb.Issue_TYPE_UNSPECIFIED {
- return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("issue type is required"))
- }
-
switch req.Msg.Issue.Type {
case v1pb.Issue_GRANT_REQUEST:
+ if req.Msg.Issue.Title == "" {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("issue title is required"))
+ }
return s.createIssueGrantRequest(ctx, req.Msg)
case v1pb.Issue_DATABASE_CHANGE:
return s.createIssueDatabaseChange(ctx, req.Msg)
@@ -1146,6 +1141,10 @@ func (s *IssueService) UpdateIssue(ctx context.Context, req *connect.Request[v1p
}
case "title":
+ // Prevent updating title if plan exists.
+ if issue.PlanUID != nil {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("cannot update issue title when plan exists"))
+ }
if req.Msg.Issue.Title == "" {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("title cannot be empty"))
}
@@ -1176,6 +1175,11 @@ func (s *IssueService) UpdateIssue(ctx context.Context, req *connect.Request[v1p
})
case "description":
+ // Prevent updating description if plan exists
+ if issue.PlanUID != nil {
+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("cannot update issue description when plan exists"))
+ }
+
patch.Description = &req.Msg.Issue.Description
issueCommentCreates = append(issueCommentCreates, &store.IssueCommentMessage{
diff --git a/backend/api/v1/issue_service_convert.go b/backend/api/v1/issue_service_convert.go
index 80cb7c0a2c..ac13145520 100644
--- a/backend/api/v1/issue_service_convert.go
+++ b/backend/api/v1/issue_service_convert.go
@@ -61,7 +61,19 @@ func (s *IssueService) convertToIssue(ctx context.Context, issue *store.IssueMes
}
if issue.PlanUID != nil {
+ plan, err := s.store.GetPlan(ctx, &store.FindPlanMessage{UID: issue.PlanUID})
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get plan by uid %v", issue.PlanUID)
+ }
issueV1.Plan = common.FormatPlan(issue.Project.ResourceID, *issue.PlanUID)
+ // Unification logic: Plan takes precedence over Issue when both exist.
+ // Use plan's title and description when available (non-empty).
+ if plan.Name != "" {
+ issueV1.Title = plan.Name
+ }
+ if plan.Description != "" {
+ issueV1.Description = plan.Description
+ }
}
if issue.PipelineUID != nil {
issueV1.Rollout = common.FormatRollout(issue.Project.ResourceID, *issue.PipelineUID)
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index 4989cdfc1d..1d781908ec 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -589,6 +589,10 @@ func convertToRollout(ctx context.Context, s *store.Store, project *store.Projec
}
if plan != nil {
rolloutV1.Plan = common.FormatPlan(project.ResourceID, plan.UID)
+ // Use plan's title when available (non-empty).
+ if plan.Name != "" {
+ rolloutV1.Title = plan.Name
+ }
}
if rollout.IssueID != nil {
diff --git a/backend/migrator/migration/3.9/0004##issue_rollout_title.sql b/backend/migrator/migration/3.9/0004##issue_rollout_title.sql
new file mode 100644
index 0000000000..8371209868
--- /dev/null
+++ b/backend/migrator/migration/3.9/0004##issue_rollout_title.sql
@@ -0,0 +1,37 @@
+-- Step 1: Backfill empty plan names and descriptions with their corresponding issue values
+UPDATE plan
+SET
+ name = CASE
+ WHEN plan.name = '' THEN issue.name
+ ELSE plan.name
+ END,
+ description = CASE
+ WHEN plan.description = '' THEN issue.description
+ ELSE plan.description
+ END
+FROM issue
+WHERE plan.id = issue.plan_id
+ AND (plan.name = '' OR plan.description = '');
+
+-- Step 2: Clear issue title (name) and description only when the related plan has non-empty values
+UPDATE issue
+SET
+ name = CASE
+ WHEN plan.name != '' THEN ''
+ ELSE issue.name
+ END,
+ description = CASE
+ WHEN plan.description != '' THEN ''
+ ELSE issue.description
+ END
+FROM plan
+WHERE issue.plan_id = plan.id;
+
+-- Step 3: Clear pipeline title (name) when it's associated with a plan
+UPDATE pipeline
+SET name = ''
+WHERE id IN (
+ SELECT DISTINCT pipeline_id
+ FROM plan
+ WHERE pipeline_id IS NOT NULL
+);
\ No newline at end of file
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 2ec40e5879..db7e0466ca 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -12,7 +12,7 @@ import (
func TestLatestVersion(t *testing.T) {
files, err := getSortedVersionedFiles()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("3.9.3"), *files[len(files)-1].version)
+ require.Equal(t, semver.MustParse("3.9.4"), *files[len(files)-1].version)
}
func TestVersionUnique(t *testing.T) {
diff --git a/backend/tests/action_test.go b/backend/tests/action_test.go
index c2bdfd1a7b..8aca05d4a2 100644
--- a/backend/tests/action_test.go
+++ b/backend/tests/action_test.go
@@ -373,7 +373,6 @@ func TestActionRolloutCommand(t *testing.T) {
a.NoError(err)
a.NotEmpty(rollouts.Msg.Rollouts, "Expected rollout to be created")
rollout := rollouts.Msg.Rollouts[0]
- a.Equal("Test Rollout", rollout.Title)
a.Equal(rollout.Name, result.OutputJSON["rollout"])
// Verify rollout completed by checking all task statuses
@@ -522,7 +521,6 @@ func TestActionRolloutCommand(t *testing.T) {
a.NoError(err)
a.NotEmpty(rollouts.Msg.Rollouts, "Expected rollout to be created")
rollout := rollouts.Msg.Rollouts[0]
- a.Equal("Multi-file Rollout", rollout.Title)
a.Equal(rollout.Name, result.OutputJSON["rollout"])
// Verify rollout completed by checking all task statuses
diff --git a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
index fbc1a49291..cae0d138a5 100644
--- a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
@@ -364,15 +364,16 @@ const createV1 = async () => {
creator: `users/${currentUserV1.value.email}`,
});
- issueCreate.title = `${t("issue.title.create-database")} '${databaseName}'`;
spec.config = {
case: "createDatabaseConfig",
value: createDatabaseConfig,
};
+ const title = `${t("issue.title.create-database")} '${databaseName}'`;
state.creating = true;
try {
const planCreate = createProto(PlanSchema, {
+ title: title,
specs: [spec],
creator: currentUserV1.value.name,
});
diff --git a/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue b/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue
index ddb2b03dc0..06676892e2 100644
--- a/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue
+++ b/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue
@@ -75,13 +75,17 @@ import { NInput, NButton } from "naive-ui";
import { computed, nextTick, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRenderMarkdown } from "@/components/MarkdownEditor";
-import { issueServiceClientConnect } from "@/grpcweb";
+import { issueServiceClientConnect, planServiceClientConnect } from "@/grpcweb";
import { emitWindowEvent } from "@/plugins";
import { pushNotification, useCurrentProjectV1 } from "@/store";
import {
IssueSchema,
UpdateIssueRequestSchema,
} from "@/types/proto-es/v1/issue_service_pb";
+import {
+ PlanSchema,
+ UpdatePlanRequestSchema,
+} from "@/types/proto-es/v1/plan_service_pb";
import { isGrantRequestIssue } from "@/utils";
import { useIssueContext } from "../../logic";
@@ -92,7 +96,12 @@ type LocalState = {
};
const { t } = useI18n();
-const { isCreating, issue, allowChange: allowEditIssue } = useIssueContext();
+const {
+ isCreating,
+ issue,
+ allowChange: allowEditIssue,
+ events,
+} = useIssueContext();
const { project } = useCurrentProjectV1();
const contentPreviewArea = ref<HTMLIFrameElement>();
@@ -127,20 +136,31 @@ const beginEdit = () => {
const saveEdit = async () => {
try {
state.isUpdating = true;
- const request = create(UpdateIssueRequestSchema, {
- issue: create(IssueSchema, {
- name: issue.value.name,
- description: state.description,
- }),
- updateMask: { paths: ["description"] },
- });
- const updated = await issueServiceClientConnect.updateIssue(request);
- Object.assign(issue.value, updated);
+ if (issue.value.plan) {
+ const request = create(UpdatePlanRequestSchema, {
+ plan: create(PlanSchema, {
+ name: issue.value.plan,
+ description: state.description,
+ }),
+ updateMask: { paths: ["description"] },
+ });
+ await planServiceClientConnect.updatePlan(request);
+ } else {
+ const request = create(UpdateIssueRequestSchema, {
+ issue: create(IssueSchema, {
+ name: issue.value.name,
+ description: state.description,
+ }),
+ updateMask: { paths: ["description"] },
+ });
+ await issueServiceClientConnect.updateIssue(request);
+ }
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("common.updated"),
});
+ events.emit("status-changed", { eager: true });
emitWindowEvent("bb.issue-field-update");
state.isEditing = false;
} finally {
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Title.vue b/frontend/src/components/IssueV1/components/HeaderSection/Title.vue
index 3ad54e15a0..f38a41765a 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Title.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Title.vue
@@ -22,19 +22,28 @@ import { NInput } from "naive-ui";
import type { CSSProperties } from "vue";
import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
-import { issueServiceClientConnect } from "@/grpcweb";
+import { issueServiceClientConnect, planServiceClientConnect } from "@/grpcweb";
import { emitWindowEvent } from "@/plugins";
import { pushNotification } from "@/store";
import {
IssueSchema,
UpdateIssueRequestSchema,
} from "@/types/proto-es/v1/issue_service_pb";
+import {
+ PlanSchema,
+ UpdatePlanRequestSchema,
+} from "@/types/proto-es/v1/plan_service_pb";
import { useIssueContext } from "../../logic";
type ViewMode = "EDIT" | "VIEW";
const { t } = useI18n();
-const { isCreating, issue, allowChange: allowEditIssue } = useIssueContext();
+const {
+ isCreating,
+ issue,
+ allowChange: allowEditIssue,
+ events,
+} = useIssueContext();
const state = reactive({
isEditing: false,
@@ -80,15 +89,26 @@ const onBlur = async () => {
}
try {
state.isUpdating = true;
- const request = create(UpdateIssueRequestSchema, {
- issue: create(IssueSchema, {
- name: issue.value.name,
- title: state.title,
- }),
- updateMask: { paths: ["title"] },
- });
- const updated = await issueServiceClientConnect.updateIssue(request);
- Object.assign(issue.value, updated);
+ if (issue.value.plan) {
+ const request = create(UpdatePlanRequestSchema, {
+ plan: create(PlanSchema, {
+ name: issue.value.plan,
+ title: state.title,
+ }),
+ updateMask: { paths: ["title"] },
+ });
+ await planServiceClientConnect.updatePlan(request);
+ } else {
+ const request = create(UpdateIssueRequestSchema, {
+ issue: create(IssueSchema, {
+ name: issue.value.name,
+ title: state.title,
+ }),
+ updateMask: { paths: ["title"] },
+ });
+ await issueServiceClientConnect.updateIssue(request);
+ }
+ events.emit("status-changed", { eager: true });
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.ts
index d39d512734..1669ca2c5f 100644
--- a/frontend/src/components/IssueV1/logic/initialize/create.ts
+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts
@@ -74,7 +74,7 @@ const buildIssue = async (params: CreatePlanParams) => {
issue.name = `${project.name}/issues/${nextUID()}`;
issue.status = IssueStatus.OPEN;
// Only set title from query if enforceIssueTitle is false.
- if (!project.enforceIssueTitle) {
+ if (issue.type === Issue_Type.GRANT_REQUEST && !project.enforceIssueTitle) {
issue.title = query.name;
}
diff --git a/frontend/src/components/Plan/components/HeaderSection/TitleInput.vue b/frontend/src/components/Plan/components/HeaderSection/TitleInput.vue
index ab5313764c..7ca841416a 100644
--- a/frontend/src/components/Plan/components/HeaderSection/TitleInput.vue
+++ b/frontend/src/components/Plan/components/HeaderSection/TitleInput.vue
@@ -22,17 +22,13 @@ import { NInput } from "naive-ui";
import type { CSSProperties } from "vue";
import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
-import { planServiceClientConnect, issueServiceClientConnect } from "@/grpcweb";
+import { planServiceClientConnect } from "@/grpcweb";
import {
pushNotification,
useCurrentUserV1,
extractUserId,
useCurrentProjectV1,
} from "@/store";
-import {
- IssueSchema,
- UpdateIssueRequestSchema,
-} from "@/types/proto-es/v1/issue_service_pb";
import { UpdatePlanRequestSchema } from "@/types/proto-es/v1/plan_service_pb";
import { PlanSchema } from "@/types/proto-es/v1/plan_service_pb";
import { hasProjectPermissionV2 } from "@/utils";
@@ -43,19 +39,19 @@ type ViewMode = "EDIT" | "VIEW";
const { t } = useI18n();
const currentUser = useCurrentUserV1();
const { project } = useCurrentProjectV1();
-const { isCreating, plan, issue, readonly } = usePlanContext();
+const { isCreating, plan, readonly } = usePlanContext();
const state = reactive({
isEditing: false,
isUpdating: false,
- title: issue?.value ? issue?.value.title : plan.value.title,
+ title: plan.value.title,
});
// Watch for changes in issue/plan to update the title
watch(
- () => [issue?.value, plan.value],
+ () => [plan.value],
() => {
- state.title = issue?.value ? issue?.value.title : plan.value.title;
+ state.title = plan.value.title;
},
{ immediate: true }
);
@@ -111,58 +107,30 @@ const onBlur = async () => {
return;
}
- // Check if we're updating issue or plan
- if (issue?.value) {
- // Update issue title
- if (state.title === issue.value.title) {
- cleanup();
- return;
- }
- try {
- state.isUpdating = true;
- const request = create(UpdateIssueRequestSchema, {
- issue: create(IssueSchema, {
- name: issue.value.name,
- title: state.title,
- }),
- updateMask: { paths: ["title"] },
- });
- const response = await issueServiceClientConnect.updateIssue(request);
- Object.assign(issue.value, response);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
- } finally {
- cleanup();
- }
- } else {
- // Update plan title
- if (state.title === plan.value.title) {
- cleanup();
- return;
- }
- try {
- state.isUpdating = true;
- const planPatch = create(PlanSchema, {
- ...plan.value,
- title: state.title,
- });
- const request = create(UpdatePlanRequestSchema, {
- plan: planPatch,
- updateMask: { paths: ["title"] },
- });
- const response = await planServiceClientConnect.updatePlan(request);
- Object.assign(plan.value, response);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
- } finally {
- cleanup();
- }
+ // Update plan title
+ if (state.title === plan.value.title) {
+ cleanup();
+ return;
+ }
+ try {
+ state.isUpdating = true;
+ const planPatch = create(PlanSchema, {
+ ...plan.value,
+ title: state.title,
+ });
+ const request = create(UpdatePlanRequestSchema, {
+ plan: planPatch,
+ updateMask: { paths: ["title"] },
+ });
+ const response = await planServiceClientConnect.updatePlan(request);
+ Object.assign(plan.value, response);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+ } finally {
+ cleanup();
}
};
diff --git a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue
index a9dc0dd7c2..a1dc63771c 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/Sidebar.vue
@@ -19,13 +19,13 @@
{{ $t("common.description") }}
</h3>
<NInput
- v-model:value="issue.description"
+ v-model:value="plan.description"
type="textarea"
:placeholder="$t('issue.add-some-description')"
:disabled="!allowChange"
:autosize="false"
:resizable="false"
- @blur="onIssueDescriptionUpdate(issue.description)"
+ @blur="onPlanDescriptionUpdate(plan.description)"
/>
</div>
</div>
@@ -38,7 +38,7 @@ import { computed } from "vue";
import { useI18n } from "vue-i18n";
import IssueLabels from "@/components/IssueV1/components/Sidebar/IssueLabels.vue";
import { useResourcePoller } from "@/components/Plan/logic/poller";
-import { issueServiceClientConnect } from "@/grpcweb";
+import { issueServiceClientConnect, planServiceClientConnect } from "@/grpcweb";
import {
extractUserId,
pushNotification,
@@ -49,13 +49,17 @@ import {
UpdateIssueRequestSchema,
IssueStatus,
} from "@/types/proto-es/v1/issue_service_pb";
+import {
+ PlanSchema,
+ UpdatePlanRequestSchema,
+} from "@/types/proto-es/v1/plan_service_pb";
import { hasProjectPermissionV2 } from "@/utils";
import { usePlanContextWithIssue } from "../../../logic/context";
import ApprovalFlowSection from "./ApprovalFlowSection/ApprovalFlowSection.vue";
import IssueStatusSection from "./IssueStatusSection.vue";
const { t } = useI18n();
-const { issue } = usePlanContextWithIssue();
+const { plan, issue } = usePlanContextWithIssue();
const currentUser = useCurrentUserV1();
const { project } = useCurrentProjectV1();
const { refreshResources } = useResourcePoller();
@@ -91,18 +95,16 @@ const onIssueLabelsUpdate = async (labels: string[]) => {
});
};
-const onIssueDescriptionUpdate = async (description: string) => {
- const issuePatch = {
- ...issue.value,
- description,
- };
- const request = create(UpdateIssueRequestSchema, {
- issue: issuePatch,
+const onPlanDescriptionUpdate = async (description: string) => {
+ const request = create(UpdatePlanRequestSchema, {
+ plan: create(PlanSchema, {
+ name: plan.value.name,
+ description,
+ }),
updateMask: { paths: ["description"] },
});
- await issueServiceClientConnect.updateIssue(request);
- // After running checks, we need to refresh the plan and plan check runs.
- refreshResources(["issue"], true /** force */);
+ await planServiceClientConnect.updatePlan(request);
+ refreshResources(["plan"], true /** force */);
pushNotification({
module: "bytebase",
style: "SUCCESS",