You can manually use the Doctrine SchemaTool class to create SQL-diff based on only one object. You will need access to the Doctrines EntityManager - the example below assumes access to the Symfonys container.
use Doctrine\ORM\Tools\SchemaTool; $em = $this->container->get('doctrine')->getManager(); $schemaTool = new SchemaTool($em); $metadata = $em->getClassMetadata(YourEntity::class); $sqlDiff = $schemaTool->getUpdateSchemaSql([$metadata], true);
Now the $sqlDiff variable will contain an array of SQL statements needed to match the database schema with the entity mapping.
The second argument passed to SchemaTool::getUpdateSchemaSql() is important - without it, the default behavior would be to generate DROP TABLE statements for every other table that appears in your database.
source share