zend-blog-3-backend
77 строк · 2.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 Version20230620044927 extends AbstractMigration implements ContainerAwareInterface
16{
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): 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('DROP VIEW IF EXISTS `v_comments`');
36}
37
38public function down(Schema $schema): void
39{
40// this down() migration is auto-generated, please modify it to your needs
41$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
42
43$this->addSql('DROP VIEW IF EXISTS `v_comments`');
44}
45
46/**
47* @param Schema $schema
48*/
49public function postUp(Schema $schema): void
50{
51parent::postUp($schema);
52
53$sql = file_get_contents(__DIR__ . '/sql/view_comments_06.sql');
54
55$em = $this->container->get('doctrine.orm.entity_manager');
56$stmt = $em->getConnection()->prepare($sql);
57$stmt->execute();
58
59$this->write(' <comment>-></comment> CREATE VIEW `v_comments`');
60}
61
62/**
63* @param Schema $schema
64*/
65public function postDown(Schema $schema): void
66{
67parent::postDown($schema);
68
69$sql = file_get_contents(__DIR__ . '/sql/view_comments_05.sql');
70
71$em = $this->container->get('doctrine.orm.entity_manager');
72$stmt = $em->getConnection()->prepare($sql);
73$stmt->execute();
74
75$this->write(' <comment>-></comment> CREATE VIEW `v_comments`');
76}
77}
78