orm:convert-mapping
Convert mapping information between supported formats
Reverse Engineering
Reverse engineer a database using the orm:convert-mapping command.
Convert database to doctrine mapping
XML
$ php ./www/index.php orm:convert-mapping --from-database xml <path>/xml
<?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Article" table="article"> <id name="id" type="integer" column="id"> <generator strategy="IDENTITY"/> </id> <field name="title" type="string" column="title" length="255" nullable="false"/> </entity> </doctrine-mapping>
PHP
$ php ./www/index.php orm:convert-mapping --from-database php <path>/php
<?php use DoctrineORMMappingClassMetadataInfo; $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); $metadata->setPrimaryTable(array( 'name' => 'address', )); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); $metadata->mapField(array( 'fieldName' => 'id', 'columnName' => 'id', 'type' => 'integer', 'nullable' => false, 'unsigned' => false, 'id' => true, )); $metadata->mapField(array( 'fieldName' => 'name', 'columnName' => 'name', 'type' => 'string', 'nullable' => false, 'length' => 255, 'fixed' => false, )); ... $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY);
Reverse Engineering is not always working perfectly depending on special cases. It will only detect Many-To-One relations (even if they are One-To-One) and will try to create entities from Many-To-Many tables.
It also has problems with naming of foreign keys that have multiple column names.
Any Reverse Engineered Database-Schema needs considerable manual work to become a useful domain model.
orm:convert-mapping –from-database annotation /php generuje přímo php třídy entit.