更新数据库架构时执行sql脚本
执行时是否可以附加(或执行)自定义sql查询:更新数据库架构时执行sql脚本,sql,symfony,doctrine-orm,Sql,Symfony,Doctrine Orm,执行时是否可以附加(或执行)自定义sql查询: app/console doctrine:schema:update --force 我有一个创建所有视图的脚本,我希望在更新数据库架构时更新它们。当然,您可以扩展该命令并通过将EntityManager插入 命令: // src/AppBundle/Command/CustomUpdateSchemaCommand.php <?php namespace AppBundle\Command; use Doctrine\Bundle\D
app/console doctrine:schema:update --force
我有一个创建所有视图的脚本,我希望在更新数据库架构时更新它们。当然,您可以扩展该命令并通过将EntityManager
插入
命令:
// src/AppBundle/Command/CustomUpdateSchemaCommand.php
<?php
namespace AppBundle\Command;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
class CustomUpdateSchemaCommand extends UpdateSchemaDoctrineCommand
{
/** @var EntityManagerInterface */
private $em;
/**
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
parent::__construct();
}
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Hello world');
$conn = $this->em->getConnection();
$conn->exec(/* QUERY */);
return parent::execute($input, $output);
}
}
希望这有帮助。您可以在symfony上创建自定义控制台的命令:。有没有扩展条令命令的方法?看看这个@MNIFAKRAM,您很受欢迎。以防万一,你为什么不把答案投上去?你认为答案中有什么不存在的或者可能更好的吗?有时候初学者会忘了投票。对不起,我忘了。
// app/config/services.yml
app.command.custom_schema_update_command:
class: App\SportBundle\Command\CustomUpdateSchemaCommand
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: console.command }