Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions pkg/webhook/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,10 @@ func TestRenderMultiEnvPlanComment_CollapsesDDL(t *testing.T) {
"the plan summary should stay outside (below) the collapsed DDL")
}

// A single statement uses the singular "statement" in the collapse summary.
func TestRenderMultiEnvPlanComment_CollapseSummarySingular(t *testing.T) {
// A multi-environment plan with a single change is small enough to show inline,
// so its DDL is rendered directly instead of behind a <details> block while the
// plan summary still appears below.
func TestRenderMultiEnvPlanComment_SingleChangeInline(t *testing.T) {
changes := []templates.KeyspaceChangeData{{
Keyspace: "testdb",
Statements: []string{"ALTER TABLE `orders` ADD COLUMN `x` INT"},
Expand All @@ -735,6 +737,37 @@ func TestRenderMultiEnvPlanComment_CollapseSummarySingular(t *testing.T) {

rendered := templates.RenderMultiEnvPlanComment(data)

assert.NotContains(t, rendered, "<details>", "a single change renders inline, not collapsed")
assert.Contains(t, rendered, "```sql")
assert.Contains(t, rendered, "ALTER TABLE `orders` ADD COLUMN `x` int")
// The plan summary still appears (below the inline DDL).
assert.Contains(t, rendered, "📋 **Plan**")
}

// When a plan has more than one change overall — here a single DDL statement
// alongside a VSchema update — the DDL still collapses, and the summary uses the
// singular "statement" for the one statement it contains.
func TestRenderMultiEnvPlanComment_CollapseSummarySingular(t *testing.T) {
changes := []templates.KeyspaceChangeData{{
Keyspace: "testks",
Statements: []string{"ALTER TABLE `orders` ADD COLUMN `x` INT"},
VSchemaChanged: true,
VSchemaDiff: "+ vindex added",
}}
data := templates.MultiEnvPlanCommentData{
Database: "testks",
IsMySQL: false,
DatabaseType: "PlanetScale",
Environments: []string{"staging", "production"},
Plans: map[string]*templates.PlanCommentData{
"staging": {Database: "testks", Environment: "staging", IsMySQL: false, DatabaseType: "PlanetScale", Changes: changes},
"production": {Database: "testks", Environment: "production", IsMySQL: false, DatabaseType: "PlanetScale", Changes: changes},
},
Errors: map[string]string{},
}

rendered := templates.RenderMultiEnvPlanComment(data)

assert.Contains(t, rendered, "<summary>Show SQL (1 statement)</summary>")
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/webhook/templates/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,14 @@ func writeEnvironmentPlanSection(sb *strings.Builder, plan *PlanCommentData) {
return
}

// Detailed changes, collapsed so the DDL doesn't dominate the comment while
// the unsafe/lint warnings and summary below stay visible at a glance.
writeCollapsibleKeyspaceChanges(sb, *plan, totalStatements)
// Detailed changes. A single change is small enough to show inline; more
// than one is collapsed so the DDL doesn't dominate the comment while the
// unsafe/lint warnings and summary below stay visible at a glance.
if totalChanges == 1 {
writeKeyspaceChanges(sb, *plan)
} else {
writeCollapsibleKeyspaceChanges(sb, *plan, totalStatements)
}

// Unsafe changes warning
if plan.HasUnsafeChanges && len(plan.UnsafeChanges) > 0 {
Expand Down
Loading