zend-blog-3-backend

Форк
0
/
Version20170724193800.php 
78 строк · 2.2 Кб
1
<?php
2

3
namespace Application\Migrations;
4

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

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

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

28
    /**
29
     * @param Schema $schema
30
     */
31
    public function up(Schema $schema): void
32
    {
33
        // this up() migration is auto-generated, please modify it to your needs
34
        $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
     */
45
    public function down(Schema $schema): void
46
    {
47
        // this down() migration is auto-generated, please modify it to your needs
48
        $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
     */
60
    public function postUp(Schema $schema): void
61
    {
62
        parent::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

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

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

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

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