When we initially designed our project, we had a couple of entities that to date are unused (and we don't plan to implement them in the near future). Ergo I want to remove them from my project. I would proceed like this (all steps manually performed):
src/Resources/config/doctrine
src/Entity
What I would like to know: Are there any routines (e.g. console commands) that may support this procedure? For example, if I run
php app/console doctrine:schema:update --dump-sql
after having removed all relations and deleted the files, that I get the SQL statement that removes the according table(s)?
Once you have removed the entities from your code, you can use the following console command to drop the tables:
php bin/console doctrine:schema:update --complete --dump-sql
Note the use of the --complete
option.
Here are the relevant parts from the doctrine:schema:update
help text:
Options:
--complete
If defined, all assets of the database which are not relevant to the current metadata will be dropped.
[...]Help:
[...]
Finally, be aware that if the
--complete
option is passed, this task will drop all database assets (e.g. tables, etc) that are not described by the current metadata. In other words, without this option, this task leaves untouched any "extra" tables that exist in the database, but which aren't described by any metadata.Hint: If you have a database with tables that should not be managed by the ORM, you can use a DBAL functionality to filter the tables and sequences down on a global level:
$config->setFilterSchemaAssetsExpression($regexp);
to remove the table in symfony 3 you can just run a migration and the table not in use will be dropped from the DB:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With