dbal icon indicating copy to clipboard operation
dbal copied to clipboard

RENAME TABLE instead of re-creation

Open ghost opened this issue 8 years ago • 15 comments

This issue is related to the schema comparator. We use it to run migrations.

If I change the table name it will result into DROP TABLE and CREATE TABLE sql queries. This will result into a data-loss. It would be better to use the RENAME TABLE feature.

See https://github.com/doctrine/migrations/issues/461

ghost avatar May 15 '16 00:05 ghost

Which DBAL version are you using and which platform does this affect? Also some sort of information/code how to replicate this is necessary otherwise we cannot do much about it.

deeky666 avatar Jun 30 '16 17:06 deeky666

Doctrine\DBAL\Schema\Schema code for that are not platform-specific and about 12 years old now:

    public function renameTable($oldName, $newName)
    {
        $table = $this->getTable($oldName);
        $table->_setName($newName);

        $this->dropTable($oldName);
        $this->_addTable($table);

        return $this;
    }

See also: https://github.com/doctrine/migrations/issues/17

This method should not exist with such name, its a trap.

Grundik avatar May 28 '21 13:05 Grundik

At the very least this method should be removed...

Killerkiwi2005 avatar Apr 11 '23 02:04 Killerkiwi2005