I'm actually looking to map and import an existing database into a symfony 6 project.
I know we can do this by using this command :
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
But, this database is very huge and have a lot of tables. I don't want them all.
Do you know a way to "select" the tables i want to map. I know the tables that i don't want start with " _ " or " inv_ ". Perhaps there is a way to have a "where" clause ?
There is a --filer=
option in doctrine:mapping:import
but I think it's not what you're looking for.
If you migrate your codebase to symfony and doctrine and doctrineORM wasn't used before - it would be much easier just to start over and do all by your self. Yes, it's tedious, especially with a huge database, but you will end up with much "cleaner" entities and during this phase you could decide which tables to ignore.
But if you still want try to "import" somehow, consider following steps:
--no-data
).env
(change db name in DATABASE_URL
)Now try to import again with doctrine:mapping:import
. You may need to adjust some tables by repeating step 2) and 3) and then try to import again.
If import succeed, and you have a bunch of entities, now comes the boring and tedious part. You have to manually check all classes in src/Entity
.
Depending on your Database (mysql, postgreSQL, sqlite, etc) not all column-types will be exact what you want.
Furthermore, most many-to-one/one-to-many
relations and all many-to-many
junction tables will be probably converted to standalone Entities like src\CategoryToProduct.php
- which isn't right. So you have to delete them and recreate your relations by hand