Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 622
DonCallisto Avatar asked Dec 30 '15 15:12

DonCallisto


1 Answers

  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.

like image 140
Crozin Avatar answered Sep 18 '22 12:09

Crozin