For this, you can extend the command from UpdateSchemaDoctrineCommand or use it in the command Process.
I prefer the first solution and I will tell you too.
Create a command in src/Acme/AppBundle/Command/CustomUpdateSchemaDoctrineCommand.php
( For example, use a package of your own)
Then, extend it from the parent command as follows:
< br />namespace Acme\AppBundle\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony \Component\Console\Output\OutputInterface;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand;
class CustomUpdateSchemaDoctrineCommand extends UpdateSchemaDoctrineCommand
{
protected function configure ()
{
parent::configure();
$this->setName('custom:schema:update')
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Do your logic
// Update your database schema
return parent::execute($input, $output);
}
}
If you need a tool that allows SQL migration to be run, please use DoctrineMigrationsBundle
Sometimes, when you are looking for performance, you need to use a certain complexity function And triggers delegate some responsibilities to the database. I want to know what is the best practice for handling these custom sql functions to create/update when calling the doctrine:schema:update command.
The simpler solution you have (I think) is to create your own command, execute the logic internally, and call doctrine: schema: update at end.
For this, You can extend the command from UpdateSchemaDoctrineCommand or use Process in the command.
I prefer the first solution and I will tell you too.
In src/Acme/AppBundle/Command / CustomUpdateSchemaDoctrineCommand.php to create a command
(for example, use a package of your own)
Then, extend it from the parent command as follows:
namespace Acme\AppBundle\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console \Input\InputInterface;
use Symfony\Compon ent\Console\Output\OutputInterface;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand;
class CustomUpdateSchemaDoctrineCommand extends UpdateSchemaDoctrineCommand
{
protected function configure( )
{
parent::configure();
$this->setName('custom:schema:update')
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// Do your logic
// Update your database schema
return parent:: execute($input, $output);
}
}
If you need a tool that allows you to run SQL migrations, please use DoctrineMigrationsBundle