zend-blog-3-backend
78 строк · 2.2 Кб
1<?php
2
3namespace Application\Migrations;4
5use Doctrine\DBAL\Schema\Schema;6use Doctrine\Migrations\AbstractMigration;7use Symfony\Component\DependencyInjection\ContainerAwareInterface;8use Symfony\Component\DependencyInjection\ContainerInterface;9
10/**
11* Auto-generated Migration: Please modify to your needs!
12*/
13class Version20170724193800 extends AbstractMigration implements ContainerAwareInterface14{
15/**16* @var ContainerInterface
17*/
18protected $container;19
20/**21* @param ContainerInterface|null $container
22*/
23public function setContainer(ContainerInterface $container = null)24{25$this->container = $container;26}27
28/**29* @param Schema $schema
30*/
31public function up(Schema $schema): void32{33// this up() migration is auto-generated, please modify it to your needs34$this->abortIf(35$this->connection->getDatabasePlatform()->getName() !== 'mysql',36'Migration can only be executed safely on \'mysql\'.'37);38
39$this->addSql('SELECT NOW()'); // Hi phantom :)40}41
42/**43* @param Schema $schema
44*/
45public function down(Schema $schema): void46{47// this down() migration is auto-generated, please modify it to your needs48$this->abortIf(49$this->connection->getDatabasePlatform()->getName() !== 'mysql',50'Migration can only be executed safely on \'mysql\'.'51);52
53$this->addSql('DROP VIEW `v_comments`');54$this->addSql('DROP VIEW `v_commentators`');55}56
57/**58* @param Schema $schema
59*/
60public function postUp(Schema $schema): void61{62parent::postUp($schema);63
64$sql1 = file_get_contents(__DIR__ . '/sql/view_comments_01.sql');65$sql2 = file_get_contents(__DIR__ . '/sql/view_commentators_01.sql');66
67$em = $this->container->get('doctrine.orm.entity_manager');68$stmt = $em->getConnection()->prepare($sql1);69$stmt->execute();70
71$this->write(' <comment>-></comment> CREATE VIEW `v_comments`');72
73$stmt = $em->getConnection()->prepare($sql2);74$stmt->execute();75
76$this->write(' <comment>-></comment> CREATE VIEW `v_commentators`');77}78}
79