Skip to content

ESP-047: Advanced DDL — Rename Table Support #65

Description

@isaquepinheiro

Task Brief

Date: 2026-04-14
GitHub Issue: #65
Status: AWAITING IMPLEMENTATION

Description

Implement "Rename Table" support in the FluentSQL DDL API. This allows developers to generate ALTER TABLE ... RENAME TO (or equivalent) SQL strings in a database-agnostic way using the Schema entry point.

Context

The "Rename Table" feature (ESP-047 / ESP-031) is a documented but unimplemented DDL capability. Adding this feature aligns the code with the user guides and completes a key vertical in the DDL infrastructure, supporting Firebird, PostgreSQL, MySQL, MSSQL, and SQLite.

Scope

  • Define IFluentDDLAlterTableRenameTableDef and IFluentDDLAlterTableRenameTableBuilder in FluentSQL.Interfaces.pas.
  • Add AlterTableRename(const AOldName, ANewName: string): IFluentDDLAlterTableRenameTableBuilder to IFluentSchema and TFluentSchema.
  • Implement TFluentDDLAlterTableRenameTableBuilder in FluentSQL.DDL.pas.
  • Add AlterTableRenameTable method to IFluentDDLSerialize and TFluentDDLSerializeAbstract.
  • Implement dialect-specific overrides in:
    • FluentSQL.DDL.Serialize.Firebird.pas
    • FluentSQL.DDL.Serialize.PostgreSQL.pas
    • FluentSQL.DDL.Serialize.MySQL.pas
    • FluentSQL.DDL.Serialize.MSSQL.pas (using sp_rename)
    • FluentSQL.DDL.Serialize.SQLite.pas
  • Add unit tests in test.ddl.pas for all dialects and validation cases.

Out of scope

  • Renaming multiple tables in one call.
  • Support for dialects beyond the core 5 (PG, FB, MySQL, MSSQL, SQLite).
  • Execution of the generated SQL.

Acceptance criteria

  • Schema(dbnPostgreSQL).AlterTableRename('A', 'B').AsString returns 'ALTER TABLE "A" RENAME TO "B"'.
  • Schema(dbnFirebird).AlterTableRename('A', 'B').AsString returns 'ALTER TABLE "A" TO "B"'.
  • Schema(dbnMySQL).AlterTableRename('A', 'B').AsString returns 'ALTER TABLE ARENAME TOB'.
  • Schema(dbnMSSQL).AlterTableRename('A', 'B').AsString returns EXEC sp_rename 'A', 'B'.
  • Schema(dbnSQLite).AlterTableRename('A', 'B').AsString returns 'ALTER TABLE "A" RENAME TO "B"'.
  • Identifiers are correctly quoted according to dialect rules.
  • Raises EArgumentException if names are empty or identical after Trim.
  • 100% of new tests in TTestDDLAlterTableRenameTable fixture PASS.

Likely impacted files

  • Source/Core/FluentSQL.Interfaces.pas
  • Source/Core/FluentSQL.DDL.pas
  • Source/Core/FluentSQL.DDL.SerializeAbstract.pas
  • Source/Drivers/FluentSQL.DDL.Serialize.Firebird.pas
  • Source/Drivers/FluentSQL.DDL.Serialize.PostgreSQL.pas
  • Source/Drivers/FluentSQL.DDL.Serialize.MySQL.pas
  • Source/Drivers/FluentSQL.DDL.Serialize.MSSQL.pas
  • Source/Drivers/FluentSQL.DDL.Serialize.SQLite.pas
  • Test Delphi/test.ddl.pas

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions