Reputation: 6421
When I run a schema update it successfully updates the schemas for my entities, but if there are any 'non-doctrine' tables in the database it deletes them. Unfortunately, these other tables are required for the 3rd party CMS I'm using.
Is there a way to tell doctrine to update the schema for certain entities (or all of them) without deleting anything else?
Below is my existing update code. The $classes
array contains all the meta data for entity classes found in several different plugins.
//$em is an instance of EntityManager
//Psuedo Code
$classes = array(
$em->getClassMetadata('class1'),
$em->getClassMetadata('class2'),
$em->getClassMetadata('class3'),
$em->getClassMetadata('class4'),
$em->getClassMetadata('class5'),
);
//Real Code
$st = new Doctrine\ORM\Tools\SchemaTool( $em );
if ($classes)
$st->updateSchema($classes);
Upvotes: 2
Views: 1212
Reputation: 6421
This gets all of the update sql but parses out any drop statements:
$sql = $st->getUpdateSchemaSql( $classes );
$count = count($sql);
for($i=0; $i<$count; $i++)
{
if(substr($sql[$i], 0, 4) == 'DROP')
unset($sql[$i]);
}
foreach($sql as $statement)
{
$em->getConnection()->exec( $statement );
}
Upvotes: 1
Reputation: 2879
You could run the schema tool with --dump-sql
instead of --force
, copy and paste the output from --dump-sql
and run it on your database manually (of course removing the DROP
statements for the tables you want to preserve.)
Upvotes: 0