zend-blog-3-backend

Форк
0
/
Version20240825082206.php 
97 строк · 3.1 Кб
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Application\Migrations;
6

7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11

12
/**
13
 * Auto-generated Migration: Please modify to your needs!
14
 */
15
final class Version20240825082206 extends AbstractMigration implements ContainerAwareInterface
16
{
17
    /**
18
     * @var ContainerInterface
19
     */
20
    protected $container;
21

22
    /**
23
     * @param ContainerInterface|null $container
24
     */
25
    public function setContainer(ContainerInterface $container = null)
26
    {
27
        $this->container = $container;
28
    }
29

30
    public function up(Schema $schema): void
31
    {
32
        // this up() migration is auto-generated, please modify it to your needs
33
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
34

35
        $this->addSql('ALTER TABLE users ADD avatar_variant SMALLINT UNSIGNED DEFAULT 0 NOT NULL');
36
        $this->addSql('DROP VIEW IF EXISTS `v_commentators`');
37
        $this->addSql('DROP VIEW IF EXISTS `v_comments`');
38
    }
39

40
    public function down(Schema $schema): void
41
    {
42
        // this down() migration is auto-generated, please modify it to your needs
43
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
44

45
        $this->addSql('ALTER TABLE users DROP avatar_variant');
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
     */
53
    public function postUp(Schema $schema): void
54
    {
55
        parent::postUp($schema);
56

57
        $sql = file_get_contents(__DIR__ . '/sql/view_commentators_06.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_09.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
     */
77
    public function postDown(Schema $schema): void
78
    {
79
        parent::postDown($schema);
80

81
        $sql = file_get_contents(__DIR__ . '/sql/view_commentators_05.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_08.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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.