Skip to content

Renaming

Schemage uses explicit rename hints. It never guesses that a removed object and a new object represent the same data.

Rename a table

Define the table with its final name and declare the previous name on the returned DefinedTable object:

$schema->table('feedback', function (Table $t): void {
    $t->id();
    $t->text('body');
})->renamed('comments');

The desired schema contains feedback. The renamed('comments') hint tells Schemage to preserve the existing table and rename it instead of dropping comments and creating feedback.

After the migration is applied, repeated diffs remain idempotent.

Rename a column

Define the column with its final name and declare its previous name:

$t->string('full_name', 500)
    ->renamed('name');

The final column definition is used during the rename. On MySQL and MariaDB, Schemage may generate CHANGE COLUMN so the operation remains compatible with MariaDB versions that do not support RENAME COLUMN.

Renames and other changes

A rename can also change the definition:

$t->string('headline', 600)
    ->renamed('title');

This renames title to headline and applies the new length in the same operation when the driver supports it.

For SQLite table recreation, renamed columns are copied from the old source name into the new target name.