Skip to content

fix(parser-sql): Reflect ALTER/MODIFY/CHANGE COLUMN in after schema#183

Merged
mhiro2 merged 1 commit into
mainfrom
fix/parser-alter-modify-change-column
Jun 4, 2026
Merged

fix(parser-sql): Reflect ALTER/MODIFY/CHANGE COLUMN in after schema#183
mhiro2 merged 1 commit into
mainfrom
fix/parser-alter-modify-change-column

Conversation

@mhiro2
Copy link
Copy Markdown
Owner

@mhiro2 mhiro2 commented Jun 4, 2026

Summary

  • Make relune review and the ERD see ALTER TABLE ALTER/MODIFY/CHANGE COLUMN and RENAME CONSTRAINT instead of dropping them with an "unsupported" warning, so type narrowing, NOT NULL toggles, and column renames now reach the after schema.
  • MySQL MODIFY/CHANGE fully redefine a column (type, nullability, comment, inline UNIQUE/FOREIGN KEY); primary-key membership is only added (never stripped) and PK columns stay NOT NULL.
  • PostgreSQL ALTER COLUMN ... TYPE / SET|DROP NOT NULL and RENAME CONSTRAINT (PK/FK/index names) are now applied, and CHANGE reuses the RENAME COLUMN propagation so FK/index columns follow the rename.
  • Add per-dialect regression tests for the previously untested ALTER paths.

Changes

  • 5ad964d fix(parser-sql): reflect ALTER/MODIFY/CHANGE COLUMN in after schema
    • Add explicit AlterColumn, ModifyColumn, ChangeColumn, and RenameConstraint arms to the ALTER TABLE handler so type/NULL/rename edits and constraint renames mutate the parsed schema, with unknown-column/constraint diagnostics on miss.
    • Reflect MySQL MODIFY/CHANGE as full column redefinitions (type, nullability, comment, inline UNIQUE/FOREIGN KEY) that only add PK membership and keep PK columns NOT NULL, clearing cached enum values so the MySQL enum pass repopulates them; CHANGE shares the RENAME COLUMN propagation to update local FK/index columns and incoming FK targets.
    • Extract shared column-option and data-type parsing from CREATE TABLE and add per-dialect regression tests covering type narrowing, nullability, renames, enum repopulation, inline constraints, and unknown-target diagnostics.

The ALTER TABLE handler ignored AlterColumn (PostgreSQL ALTER COLUMN
... TYPE / SET|DROP NOT NULL), ModifyColumn / ChangeColumn (MySQL), and
RenameConstraint, emitting only an "unsupported" warning. Type changes,
NOT NULL toggles, and column renames never reached the after schema, so
relune review silently passed dangerous migrations and the ERD showed
stale types. Add explicit arms for all four operations: MODIFY/CHANGE
fully redefine the column (type, nullability, comment, inline UNIQUE/FK)
while only adding primary-key membership, and PK columns stay NOT NULL.
CHANGE reuses the RENAME COLUMN propagation so local FK/index columns
and incoming FK targets follow the rename. Share column-option and
data-type parsing with CREATE TABLE, and add per-dialect regression
tests covering type narrowing, nullability, renames, enum repopulation,
inline constraints, and unknown-target diagnostics.
@mhiro2 mhiro2 self-assigned this Jun 4, 2026
@mhiro2 mhiro2 added the bug Something isn't working label Jun 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

Code Metrics Report

main (3b356ee) #183 (8367214) +/-
Coverage 94.4% 94.4% +0.0%
Test Execution Time 3m28s 1m33s -1m55s
Details
  |                     | main (3b356ee) | #183 (8367214) |  +/-   |
  |---------------------|----------------|----------------|--------|
+ | Coverage            |          94.4% |          94.4% |  +0.0% |
  |   Files             |            100 |            100 |      0 |
  |   Lines             |          36858 |          37038 |   +180 |
+ |   Covered           |          34801 |          34973 |   +172 |
+ | Test Execution Time |          3m28s |          1m33s | -1m55s |

Code coverage of files in pull request scope (85.2% → 87.5%)

Files Coverage +/- Status
crates/relune-parser-sql/src/alter_table.rs 86.6% +3.3% modified
crates/relune-parser-sql/src/create_table.rs 90.3% +0.6% modified

Reported by octocov

@mhiro2 mhiro2 merged commit ec58183 into main Jun 4, 2026
4 checks passed
@mhiro2 mhiro2 deleted the fix/parser-alter-modify-change-column branch June 4, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant