Skip to content

Rename DDL: close dialect gaps, add capability flags, atomic table swap, and rename for the remaining schema objects #47

Description

@stbischof

Current state

DdlGenerator already offers renameTable, renameColumn (incl. the ColumnReference overload), renameIndex, and renameConstraint with ANSI-style defaults (ALTER TABLE … RENAME TO, … RENAME COLUMN … TO …, ALTER INDEX … RENAME TO, … RENAME CONSTRAINT … TO …).

Verified per dialect (offline tests exist for the first four; H2/SQLite/DuckDB/Derby were probed live against in-memory instances):

Dialect Table Column Index Constraint
PostgreSQL
Oracle
SQL Server (sp_rename, incl. the mandatory 'COLUMN' argument)
MySQL / MariaDB ≥ 10.5.2 ✅ (ALTER TABLE … RENAME INDEX) null (unsupported)
H2
SQLite ❌ invalid SQL ❌ invalid SQL
DuckDB ❌ "Not implemented" ❌ "Not implemented"
Derby ❌ — every default is a syntax error
ClickHouse ❌ needs RENAME TABLE

Requirements

1. Capability flags — always checkable before rendering

Following the established pattern (DialectCapabilitiesProvider.supportsXyz() aggregated into the DdlCapabilities record via getDdlCapabilities()), add flags so a caller can always probe before calling the generator instead of interpreting a null return:

  • supportsRenameTable(), supportsRenameColumn(), supportsRenameIndex(), supportsRenameConstraint()
  • supportsAtomicMultiRenameTable() (see 3), supportsRenameView(), supportsRenameTrigger(), supportsRenameSequence() (see 4)

Contract: a generator method returns valid SQL exactly when its flag is true, and null otherwise — the flag and the generator must never disagree.

2. Fix the broken dialects

  • Derby: override with RENAME TABLE t TO n, RENAME COLUMN t.c TO n, RENAME INDEX o TO n (all verified live); renameConstraint → unsupported.
  • SQLite: renameIndex/renameConstraint → unsupported (drop + recreate is the only option).
  • DuckDB: renameIndex/renameConstraint → unsupported. Document that RENAME COLUMN fails on columns carrying an index ("Dependency Error").
  • ClickHouse: renameTableRENAME TABLE a TO b; index/constraint → unsupported.

3. Atomic multi-rename / table swap

New renameTables(List<…>): default renders one statement per pair; the MySQL family overrides with a single atomic RENAME TABLE a TO tmp, b TO a, tmp TO b; ClickHouse maps to RENAME TABLE/EXCHANGE TABLES. Capability: supportsAtomicMultiRenameTable().

4. Rename for the remaining schema objects

renameView, renameTrigger, renameSequence (sequences are currently absent from DdlGenerator altogether — add create/drop alongside). PostgreSQL: ALTER VIEW/SEQUENCE/TRIGGER … RENAME TO; Oracle: RENAME / ALTER TRIGGER … RENAME TO; SQL Server: sp_rename; unsupported elsewhere → flag false.

5. Version-aware fallback for old MySQL/MariaDB

MariaDB < 10.5.2 / MySQL < 8.0 have no RENAME COLUMN; they need CHANGE old new <full column definition> — anything omitted from the definition is silently dropped, so the definition must be passed in explicitly. Add a renameColumn(TableReference, String, String, ColumnMetaData) overload (mirroring alterColumnType) and gate on productVersion, which the dialect already compares numerically elsewhere. supportsRenameColumn() stays true; without metadata on an old version the metadata-less overload returns null.

Acceptance criteria

  • Every rename* generator method has a matching capability flag, exposed through DdlCapabilities.
  • Offline sqlgen tests for every dialect × operation, including the unsupported (null) cases.
  • Flag and generator agree for every dialect × operation combination.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions