Skip to content

Use native SQLite ALTER TABLE RENAME COLUMN#159

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/remove-sqlite-hacks
Draft

Use native SQLite ALTER TABLE RENAME COLUMN#159
Copilot wants to merge 3 commits intomasterfrom
copilot/remove-sqlite-hacks

Conversation

Copy link

Copilot AI commented Feb 6, 2026

SQLite 3.25.0+ supports ALTER TABLE ... RENAME COLUMN natively. The codebase was using a workaround that recreated the entire table.

Changes

  • Removed SQLiteTransformationProvider.RenameColumn override (82 lines)

    • Previously: Created temp table → copied data → dropped original → renamed temp → recreated indexes
    • Now: Uses base class implementation that generates ALTER TABLE table RENAME COLUMN old TO new
    • Native command automatically updates all references in indexes, triggers, foreign keys, and views
  • RemoveColumn unchanged

    • SQLite's native DROP COLUMN (3.35.0+) cannot drop PRIMARY KEY, UNIQUE, or foreign key-referenced columns
    • RecreateTable approach retained for full feature support
  • AddColumn unchanged

    • SQLite's native ADD COLUMN (3.1.3+) cannot add PRIMARY KEY or UNIQUE columns
    • RecreateTable approach retained for full feature support and schema normalization
    • Added documentation explaining the limitations
  • RemoveTable (DropTable) - No changes needed

    • Already uses native DROP TABLE command (no SQLite override exists)

Example

// Before: Required PRAGMA foreign_keys = OFF, recreated entire table
provider.RenameColumn("Users", "EmailAddress", "Email");

// After: Simple native SQL command
// ALTER TABLE Users RENAME COLUMN "EmailAddress" TO "Email"

All 134 SQLite tests pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>Remove hacks for some SQlite features</issue_title>
<issue_description>Sqlite supports more DDL features natively:

RenameColumn, DropColumn, ...</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…OLUMN

Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove hacks for SQLite DDL features Use native SQLite ALTER TABLE RENAME COLUMN Feb 6, 2026
Copilot AI requested a review from jogibear9988 February 6, 2026 08:04
@jogibear9988
Copy link
Member

@copilot and what about DropColumn? is this not also natively supported?

@jogibear9988
Copy link
Member

@copilot and droptable and dd column? seems all to be now supprted.

Copy link
Author

Copilot AI commented Feb 6, 2026

@copilot and what about DropColumn? is this not also natively supported?

Yes, SQLite 3.35.0+ added native ALTER TABLE ... DROP COLUMN, but it has significant limitations that would break existing functionality:

Native DROP COLUMN cannot drop:

  • PRIMARY KEY columns
  • UNIQUE columns
  • Columns referenced by foreign keys
  • Columns with indexes

Current RecreateTable provides:

  • Auto-cleanup of foreign keys in other tables pointing to the dropped column
  • Ability to drop any column type
  • Consistent behavior across all scenarios

The existing tests expect these behaviors (e.g., dropping PK columns, auto-removing FKs). Switching to native DROP COLUMN would require either:

  1. Accepting these limitations (breaking change)
  2. Implementing a complex hybrid that uses native for simple columns, RecreateTable for others

For now, I kept RecreateTable for DROP COLUMN to maintain compatibility. RenameColumn was straightforward since SQLite's native command handles all references automatically.

Copy link
Author

Copilot AI commented Feb 6, 2026

@copilot and droptable and dd column? seems all to be now supprted.

You're right! Looking at the code:

  1. DROP TABLE: Already uses native DROP TABLE (no SQLite override)
  2. ADD COLUMN: Currently uses RecreateTable but could use native ALTER TABLE ADD COLUMN

Native ADD COLUMN has been in SQLite since 3.1.3 (2005) with only minor limitations (can't add PK/UNIQUE columns). The current tests add simple nullable columns, which work fine with native support.

I'll update AddColumn to use the native command.

…support

Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove hacks for some SQlite features

2 participants