Skip to content

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

refactor: copy plan title/description to issues instead of using COALESCE (#18730)

Danny Xu9bae444742e1
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 481d6a1a65..163cf9308c 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -447,6 +447,7 @@ func (s *IssueService) CreateIssue(ctx context.Context, req *connect.Request[v1p
func (s *IssueService) buildIssueMessage(ctx context.Context, project *store.ProjectMessage, userEmail string, request *v1pb.CreateIssueRequest) (*store.IssueMessage, error) {
var planUID *int64
var grantRequest *storepb.GrantRequest
+ var title, description string
// Type-specific validation and preparation
switch request.Issue.Type {
@@ -500,6 +501,9 @@ func (s *IssueService) buildIssueMessage(ctx context.Context, project *store.Pro
Expiration: request.Issue.GrantRequest.Expiration,
}
+ title = request.Issue.Title
+ description = request.Issue.Description
+
case v1pb.Issue_DATABASE_CHANGE, v1pb.Issue_DATABASE_EXPORT:
// Validate and fetch plan (shared logic for both types)
if request.Issue.Plan == "" {
@@ -519,6 +523,16 @@ func (s *IssueService) buildIssueMessage(ctx context.Context, project *store.Pro
return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("plan %d not found in project %s", planID, project.ResourceID))
}
planUID = &plan.UID
+
+ // Use plan's title and description as defaults if not provided by request
+ title = request.Issue.Title
+ if title == "" {
+ title = plan.Name
+ }
+ description = request.Issue.Description
+ if description == "" {
+ description = plan.Description
+ }
default:
return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("unknown issue type %q", request.Issue.Type))
}
@@ -534,10 +548,10 @@ func (s *IssueService) buildIssueMessage(ctx context.Context, project *store.Pro
ProjectID: project.ResourceID,
CreatorEmail: userEmail,
PlanUID: planUID,
- Title: request.Issue.Title,
+ Title: title,
Status: storepb.Issue_OPEN,
Type: issueType,
- Description: request.Issue.Description,
+ Description: description,
Payload: &storepb.Issue{
GrantRequest: grantRequest,
Approval: &storepb.IssuePayloadApproval{
diff --git a/backend/migrator/migration/3.14/0017##backfill_issue_titles.sql b/backend/migrator/migration/3.14/0017##backfill_issue_titles.sql
new file mode 100644
index 0000000000..ad4f558d9b
--- /dev/null
+++ b/backend/migrator/migration/3.14/0017##backfill_issue_titles.sql
@@ -0,0 +1,10 @@
+-- Backfill issue titles and descriptions from their associated plans.
+-- Issues created from plans previously had empty titles/descriptions and relied on COALESCE.
+-- This migration makes the relationship explicit by copying plan data into issue records.
+UPDATE issue
+SET
+ name = plan.name,
+ description = plan.description
+FROM plan
+WHERE issue.plan_id = plan.id
+ AND issue.name = '';
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index d4e7e45ca1..dcd4740228 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -12,8 +12,8 @@ import (
func TestLatestVersion(t *testing.T) {
files, err := getSortedVersionedFiles()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("3.14.16"), *files[len(files)-1].version)
- require.Equal(t, "migration/3.14/0016##plan_webhook_delivery.sql", files[len(files)-1].path)
+ require.Equal(t, semver.MustParse("3.14.17"), *files[len(files)-1].version)
+ require.Equal(t, "migration/3.14/0017##backfill_issue_titles.sql", files[len(files)-1].path)
}
func TestVersionUnique(t *testing.T) {
diff --git a/backend/store/issue.go b/backend/store/issue.go
index d08789b8bf..3b9ddff662 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -259,7 +259,7 @@ func (s *Store) ListIssues(ctx context.Context, find *FindIssueMessage) ([]*Issu
searchCondition.Or("issue.ts_vector @@ query")
orderByClause = "ORDER BY ts_rank(issue.ts_vector, query) DESC, issue.id DESC"
}
- searchCondition.Or("plan.name ILIKE ?", "%"+*v+"%")
+ searchCondition.Or("issue.name ILIKE ?", "%"+*v+"%")
where.And("(?)", searchCondition)
}
if len(find.StatusList) != 0 {
@@ -281,13 +281,12 @@ func (s *Store) ListIssues(ctx context.Context, find *FindIssueMessage) ([]*Issu
issue.updated_at,
issue.project,
issue.plan_id,
- COALESCE(plan.name, issue.name) AS name,
+ issue.name,
issue.status,
issue.type,
- COALESCE(plan.description, issue.description) AS description,
+ issue.description,
issue.payload
FROM ?
- LEFT JOIN plan ON issue.plan_id = plan.id
`, from)
if where.Len() > 0 {
q.Space("WHERE ?", where)
@@ -481,10 +480,9 @@ func (s *Store) BackfillIssueTSVector(ctx context.Context) error {
selectQuery := qb.Q().Space(`
SELECT
issue.id,
- COALESCE(plan.name, issue.name) AS name,
- COALESCE(plan.description, issue.description) AS description
+ issue.name,
+ issue.description
FROM issue
- LEFT JOIN plan ON issue.plan_id = plan.id
WHERE issue.ts_vector IS NULL
ORDER BY issue.id
LIMIT ?