Doctrine2 Migration Using DBAL instead of $this->addSql

前端 未结 2 1037
走了就别回头了
走了就别回头了 2021-02-07 17:43

So I\'ve done a bunch of Doctrine2 migrations (https://github.com/doctrine/migrations) but I have a question for a new migration I\'m trying to do.

I\'ve been digging in

2条回答
  •  旧时难觅i
    2021-02-07 18:16

    FYI, latest docs show this example that is even better with a "postUp" method

    http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html

    // ...
    use Symfony\Component\DependencyInjection\ContainerAwareInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    class Version20130326212938 extends AbstractMigration implements ContainerAwareInterface
    {
    
        private $container;
    
        public function setContainer(ContainerInterface $container = null)
        {
            $this->container = $container;
        }
    
        public function up(Schema $schema)
        {
            // ... migration content
        }
    
        public function postUp(Schema $schema)
        {
            $em = $this->container->get('doctrine.orm.entity_manager');
            // ... update the entities
        }
    }
    

提交回复
热议问题