Timo
Timo

Reputation: 693

Creating/updating schema from Doctrine entities

I'm using Doctrine with Zend Framework. I have to create both the DB schema and the Doctrine entities with annotations.

Since the annotations already contain the information, it should be possible to create/update the schema based on them. I don't want to reinvent the wheel, so I was wondering whether that kind of logic already existed?

Upvotes: 1

Views: 6759

Answers (2)

k0pernikus
k0pernikus

Reputation: 66787

There's the Doctrine SchemaTool (ORM/Tools/SchemaTool).

$meta = array(
    $this->_em->getClassMetadata('Customer')
);

$tool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
$tool->updateSchema($meta);

Upvotes: 0

K. Norbert
K. Norbert

Reputation: 10684

You can use the doctrine CLI, for a lot of doctrine related tasks. I'm not sure how doctrine is integrated into Zend, but look for the doctrine.php, and invoke it like this:

php doctrine.php orm:schema-tool:update --force

This will update your db to match your schema definitions. You can also use

php doctrine.php orm:schema-tool:update --dump-sql

To see what SQL commands would doctrine run. See the Tools section in the doctrine docs for more information.

Upvotes: 4

Related Questions