Skip to content

sqlgen: ADD COLUMN never emits FIRST/AFTER — declared column position ignored #88

Description

@orian

Symptom

alterTableSQL ADD COLUMN (internal/loader/hcl/sqlgen.go:724-725) never emits FIRST/AFTER; columnDefSQL has no positional clause.

Impact

New columns always land at the end of the table regardless of their declared position in HCL, so the live column order permanently diverges from the schema file. If column order is later used in comparisons or round-trip fidelity checks, this shows up as unfixable drift.

Fix direction

When a column is added, compute its declared neighbor and emit ADD COLUMN ... AFTER <prev> (or FIRST). Optionally also detect pure reorders and emit MODIFY COLUMN ... AFTER ....

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

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