Reputation: 53
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 ?
Upvotes: 3
Views: 9572
Reputation: 1548
--filter does not work anymore in case of DB Oracle for mee (SF6). So I modify temporarily vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
foreach ($this->sm->listTables() as $table) {
$tableName = $table->getName();
if (str_contains($tableName, 'XXXXX')) {
Upvotes: 1
Reputation: 396
If you happen to have a diagram of your database done with MySQL Workbench, you can use these tools to export your diagram into working entities :
First you setup this with composer: https://github.com/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter And then this : https://github.com/mysql-workbench-schema-exporter/doctrine2-exporter
Then you run the following command to get to know more how to use it :
php composer require --dev mysql-workbench-schema-exporter/doctrine2-exporter
You have plenty of options to parameter desired output, entities namespace and so on, everything is described in the second github rep if you want to use the doctrine2 ORM export format.
Upvotes: 3
Reputation: 3115
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
Upvotes: 1