zend-blog-3-backend
97 строк · 3.2 Кб
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 Version20230626214411 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('ALTER TABLE commentators ADD gender SMALLINT DEFAULT 1 NOT NULL COMMENT \'1: male, 2: female\', DROP force_image');36$this->addSql('DROP VIEW IF EXISTS `v_commentators`');37$this->addSql('DROP VIEW IF EXISTS `v_comments`');38}39
40public function down(Schema $schema): void41{42// this down() migration is auto-generated, please modify it to your needs43$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');44
45$this->addSql('ALTER TABLE commentators ADD force_image TINYINT(1) DEFAULT 0 NOT NULL, DROP gender');46$this->addSql('DROP VIEW IF EXISTS `v_commentators`');47$this->addSql('DROP VIEW IF EXISTS `v_comments`');48}49
50/**51* @param Schema $schema
52*/
53public function postUp(Schema $schema): void54{55parent::postUp($schema);56
57$sql = file_get_contents(__DIR__ . '/sql/view_commentators_04.sql');58
59$em = $this->container->get('doctrine.orm.entity_manager');60$stmt = $em->getConnection()->prepare($sql);61$stmt->executeQuery();62
63$this->write(' <comment>-></comment> CREATE VIEW `v_commentators`');64
65$sql = file_get_contents(__DIR__ . '/sql/view_comments_07.sql');66
67$em = $this->container->get('doctrine.orm.entity_manager');68$stmt = $em->getConnection()->prepare($sql);69$stmt->executeQuery();70
71$this->write(' <comment>-></comment> CREATE VIEW `v_comments`');72}73
74/**75* @param Schema $schema
76*/
77public function postDown(Schema $schema): void78{79parent::postDown($schema);80
81$sql = file_get_contents(__DIR__ . '/sql/view_commentators_03.sql');82
83$em = $this->container->get('doctrine.orm.entity_manager');84$stmt = $em->getConnection()->prepare($sql);85$stmt->executeQuery();86
87$this->write(' <comment>-></comment> CREATE VIEW `v_commentators`');88
89$sql = file_get_contents(__DIR__ . '/sql/view_comments_06.sql');90
91$em = $this->container->get('doctrine.orm.entity_manager');92$stmt = $em->getConnection()->prepare($sql);93$stmt->executeQuery();94
95$this->write(' <comment>-></comment> CREATE VIEW `v_comments`');96}97}
98