zend-blog-3-backend
63 строки · 2.1 Кб
1<?php
2
3declare(strict_types=1);4
5namespace Application\Migrations;6
7use Doctrine\DBAL\Schema\Schema;8use Doctrine\Migrations\AbstractMigration;9
10/**
11* Auto-generated Migration: Please modify to your needs!
12*/
13final class Version20230609101954 extends AbstractMigration14{
15public function up(Schema $schema): void16{17// this up() migration is auto-generated, please modify it to your needs18$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');19
20$this->addSql(<<<SQL21CREATE TABLE `tracking_agent_temp` (22`id` int unsigned NOT NULL,23`created_at` datetime NOT NULL,24PRIMARY KEY (`id`)25) ENGINE InnoDB;26SQL
27);28
29$this->addSql(<<<SQL30INSERT INTO tracking_agent_temp (id, created_at)31SELECT
32ta.id,33MIN(tar.time_created) AS tar_time_created34FROM `tracking_agent` AS ta35LEFT JOIN tracking_archive AS tar ON ta.id = tar.user_agent_id36WHERE ta.created_at IS NULL37GROUP BY ta.id38SQL
39);40
41$this->addSql(<<<SQL42UPDATE tracking_agent, tracking_agent_temp43SET tracking_agent.created_at = tracking_agent_temp.created_at44WHERE
45tracking_agent.created_at IS NULL46AND tracking_agent.id = tracking_agent_temp.id47SQL
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
55public function down(Schema $schema): void56{57// this down() migration is auto-generated, please modify it to your needs58$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