zend-blog-3-backend
95 строк · 3.0 Кб
1<?php
2
3declare(strict_types=1);4
5namespace Application\Migrations;6
7use Doctrine\DBAL\Schema\Schema;8use Doctrine\Migrations\AbstractMigration;9use Symfony\Component\DependencyInjection\ContainerAwareInterface;10use Symfony\Component\DependencyInjection\ContainerInterface;11
12/**
13* Auto-generated Migration: Please modify to your needs!
14*/
15final class Version20240811070520 extends AbstractMigration implements ContainerAwareInterface16{
17/**18* @var ContainerInterface
19*/
20protected $container;21
22/**23* @param ContainerInterface|null $container
24*/
25public function setContainer(ContainerInterface $container = null)26{27$this->container = $container;28}29
30public function up(Schema $schema): void31{32// this up() migration is auto-generated, please modify it to your needs33$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');34
35$this->addSql('DROP VIEW IF EXISTS `v_commentators`');36$this->addSql('DROP VIEW IF EXISTS `v_comments`');37}38
39public function down(Schema $schema): void40{41// this down() migration is auto-generated, please modify it to your needs42$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');43
44$this->addSql('DROP VIEW IF EXISTS `v_commentators`');45$this->addSql('DROP VIEW IF EXISTS `v_comments`');46}47
48/**49* @param Schema $schema
50*/
51public function postUp(Schema $schema): void52{53parent::postUp($schema);54
55$sql = file_get_contents(__DIR__ . '/sql/view_commentators_05.sql');56
57$em = $this->container->get('doctrine.orm.entity_manager');58$stmt = $em->getConnection()->prepare($sql);59$stmt->executeQuery();60
61$this->write(' <comment>-></comment> CREATE VIEW `v_commentators`');62
63$sql = file_get_contents(__DIR__ . '/sql/view_comments_08.sql');64
65$em = $this->container->get('doctrine.orm.entity_manager');66$stmt = $em->getConnection()->prepare($sql);67$stmt->executeQuery();68
69$this->write(' <comment>-></comment> CREATE VIEW `v_comments`');70}71
72/**73* @param Schema $schema
74*/
75public function postDown(Schema $schema): void76{77parent::postDown($schema);78
79$sql = file_get_contents(__DIR__ . '/sql/view_commentators_04.sql');80
81$em = $this->container->get('doctrine.orm.entity_manager');82$stmt = $em->getConnection()->prepare($sql);83$stmt->executeQuery();84
85$this->write(' <comment>-></comment> CREATE VIEW `v_commentators`');86
87$sql = file_get_contents(__DIR__ . '/sql/view_comments_07.sql');88
89$em = $this->container->get('doctrine.orm.entity_manager');90$stmt = $em->getConnection()->prepare($sql);91$stmt->executeQuery();92
93$this->write(' <comment>-></comment> CREATE VIEW `v_comments`');94}95}
96