zend-blog-3-backend
39 строк · 1.9 Кб
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 Version20230616153217 extends AbstractMigration
14{
15public 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('DROP INDEX UNIQ_5F9E962AE46417AB ON comments');
21$this->addSql('ALTER TABLE comments ADD ip_long INT UNSIGNED DEFAULT NULL AFTER ip_addr, DROP disqus_id');
22$this->addSql('UPDATE comments AS c, geo_location AS g SET c.ip_long = g.ip_long WHERE c.ip_addr IS NOT NULL AND g.ip_long = INET_ATON(c.ip_addr)');
23$this->addSql('CREATE INDEX IDX_5F9E962A28F0F5E7 ON comments (ip_long)');
24$this->addSql('ALTER TABLE geo_location ADD count_of_check SMALLINT UNSIGNED DEFAULT 0 NOT NULL');
25$this->addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962A28F0F5E7 FOREIGN KEY (ip_long) REFERENCES geo_location (ip_long) ON DELETE SET NULL');
26}
27
28public function down(Schema $schema): void
29{
30// this down() migration is auto-generated, please modify it to your needs
31$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
32
33$this->addSql('ALTER TABLE comments DROP FOREIGN KEY FK_5F9E962A28F0F5E7');
34$this->addSql('ALTER TABLE geo_location DROP count_of_check');
35$this->addSql('DROP INDEX IDX_5F9E962A28F0F5E7 ON comments');
36$this->addSql('ALTER TABLE comments ADD disqus_id BIGINT DEFAULT NULL, DROP ip_long');
37$this->addSql('CREATE UNIQUE INDEX UNIQ_5F9E962AE46417AB ON comments (disqus_id)');
38}
39}
40