zend-blog-3-backend

Форк
0
/
Version20230609101954.php 
63 строки · 2.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

10
/**
11
 * Auto-generated Migration: Please modify to your needs!
12
 */
13
final class Version20230609101954 extends AbstractMigration
14
{
15
    public function up(Schema $schema): void
16
    {
17
        // this up() migration is auto-generated, please modify it to your needs
18
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
19

20
        $this->addSql(<<<SQL
21
CREATE TABLE `tracking_agent_temp` (
22
  `id` int unsigned NOT NULL,
23
  `created_at` datetime NOT NULL,
24
  PRIMARY KEY (`id`)
25
) ENGINE InnoDB;
26
SQL
27
        );
28

29
        $this->addSql(<<<SQL
30
INSERT INTO tracking_agent_temp (id, created_at)
31
SELECT
32
  ta.id,
33
  MIN(tar.time_created) AS tar_time_created
34
FROM `tracking_agent` AS ta
35
LEFT JOIN tracking_archive AS tar ON ta.id = tar.user_agent_id
36
WHERE ta.created_at IS NULL
37
GROUP BY ta.id
38
SQL
39
        );
40

41
        $this->addSql(<<<SQL
42
UPDATE tracking_agent, tracking_agent_temp
43
SET tracking_agent.created_at = tracking_agent_temp.created_at
44
WHERE
45
    tracking_agent.created_at IS NULL
46
    AND tracking_agent.id = tracking_agent_temp.id
47
SQL
48
        );
49

50
        $this->addSql('DROP TABLE tracking_agent_temp');
51
        $this->addSql('ALTER TABLE tracking_agent CHANGE created_at created_at DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3) NOT NULL COMMENT \'(DC2Type:milliseconds_dt)\'');
52
        $this->addSql('ALTER TABLE comments DROP last_update_copy');
53
    }
54

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

60
        $this->addSql('ALTER TABLE comments ADD last_update_copy DATETIME(3) DEFAULT NULL COMMENT \'(DC2Type:milliseconds_dt)\'');
61
        $this->addSql('ALTER TABLE tracking_agent CHANGE created_at created_at DATETIME(3) DEFAULT NULL COMMENT \'(DC2Type:milliseconds_dt)\'');
62
    }
63
}
64

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

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

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

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