Skip to content

diff/sqlgen: support extend-only MODIFY ORDER BY instead of always unsafe/recreate #89

Description

@orian

Symptom

Every ORDER BY change is classed unsafe/recreate (internal/loader/hcl/diff.go:263-266). ClickHouse supports ALTER TABLE ... MODIFY ORDER BY in place when the change is extend-only (appending new columns that were just added in the same ALTER).

Impact

A common, safe evolution (add a column and extend the sorting key with it) is reported as "requires recreating the table" and produces no runnable DDL.

Fix direction

Detect the extend-only case (new ORDER BY = old ORDER BY + newly-added columns) and emit ADD COLUMN ..., MODIFY ORDER BY (...) in one ALTER; keep the unsafe/recreate classification for everything else.

Found in the 2026-07-02 deep-dive audit (docs/plans/2026-07-02-deep-dive-improvement-areas.md, B5).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions