Support ALTER COLUMN on SQLite via table rebuild#512
Merged
Conversation
65f16f1 to
07efcab
Compare
07efcab to
9122cfe
Compare
added 2 commits
June 25, 2026 11:35
SQLite has no `ALTER TABLE … ALTER COLUMN`, yet the SQLite formatter emitted the SQL-Server form verbatim, so an AlterColumn migration failed at runtime with `near "ALTER": syntax error`. This surfaced in downstream lup2dbtool-generated migrations (e.g. widening a column to `long varchar`), which translate to `plan.AlterTable(...).AlterColumn(...)` and run through this library. Route SQLite AlterColumn through the existing sentinel + table-rebuild path used for foreign-key changes: - SQLiteFormatter emits `-- LIGHTWEIGHT_SQLITE_GUARD: ALTER_COLUMN` carrying the new column type and nullability. - The migration executor recognises the sentinel and rebuilds the table from its stored CREATE TABLE, rewriting only the target column's type and nullability while preserving other columns, the primary key, and inline constraints (RewriteSqliteColumnDefinition + StripNullabilityKeywords), then copies the data across via the shared RebuildSqliteTable helper. MS SQL Server and PostgreSQL continue to ALTER the column in place — those formatter branches are untouched. Tests: - QueryBuilderTests: formatter output for SQLite (sentinel), PostgreSQL, and SQL Server, for both nullability values and a parameterized type. - MigrationTests: CI-verified end-to-end SQLite rebuild (run through MigrationManager so the guard executor fires) — type widen with data/PK/other columns preserved, NOT NULL↔NULL both directions, two folded AlterColumn calls, and the missing-column error path leaving the table intact. Signed-off-by: Christian Parpart <c.parpart@lastrada.net>
The previous commit's local clang-format run used v20; CI enforces v22, which formats two pre-existing blocks (an SqlInsertDataPlan initializer and the `m3 "drop temp"` FoldStub) differently. Restore them to master's v22 form so the "Check C++ style" job passes. No behavioural change. Signed-off-by: Christian Parpart <c.parpart@lastrada.net>
9122cfe to
9ecf63e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SQLite has no
ALTER TABLE … ALTER COLUMN, yet the SQLite query formatter emitted the SQL-Server form verbatim. AnyAlterColumnmigration therefore failed at runtime withnear "ALTER": syntax error— for example a downstream lup2dbtool-generated migration that widens a column tolong varchar, which translates toplan.AlterTable(...).AlterColumn(...)and runs through this library.This routes SQLite
AlterColumnthrough the same sentinel + table-rebuild path already used for foreign-key changes, so SQLite reaches real parity with MS SQL Server and PostgreSQL. Those two dialects continue to ALTER the column in place; their formatter branches are untouched.Changes
-- LIGHTWEIGHT_SQLITE_GUARD: ALTER_COLUMNsentinel carrying the new column type and nullability instead of an unsupportedALTER COLUMNstatement.CREATE TABLE, rewriting only the target column's type and nullability while preserving the other columns, the primary key, and inline constraints (RewriteSqliteColumnDefinition+StripNullabilityKeywords), then copy the data across via the sharedRebuildSqliteTablehelper.MigrationManager(so the guard executor actually fires and the--test-env=sqlite3CI leg verifies it) covering type widening with data/PK/other-column preservation,NOT NULL↔NULLin both directions, two foldedAlterColumncalls, and a missing-column error path that leaves the table intact.