symfonydoctrine-ormdoctrine-migrations

Rename table name with Doctrine migrations


I've searched pretty much everywhere but I wasn't able to find anything.

Is there a command or a procedure to change the name of a table (so inside doctrine annotation) without loosing data?

Basically, something that will produce something like

RENAME TABLE old_table TO new_table;

or

ALTER TABLE old_table RENAME new_table;

MySQL commands taken from here

Should I write manually the migration file with doctrine:migrations:generate?


Solution

    1. Change table name for given entity.

      /** @Entity @Table(name="new_table_name") */
      class MyEntity { ... }
      
    2. Generate a new migration.

    3. Erase contents of up() and down() methods and replace them with custom SQL (ALTER TABLE ... RENAME TO ...).

    Keep in mind that migration generator is meant as utility/semi-automatic tool.