zend-blog-3-backend

Форк
0
/
Version20230617072331.php 
38 строк · 1.9 Кб
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 Version20230617072331 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('ALTER TABLE tracking ADD ip_long INT UNSIGNED DEFAULT NULL AFTER ip_addr');
21
        $this->addSql('ALTER TABLE tracking_archive ADD ip_long INT UNSIGNED DEFAULT NULL AFTER ip_addr');
22
        $this->addSql('UPDATE tracking AS t, geo_location AS g SET t.ip_long = g.ip_long WHERE t.ip_addr IS NOT NULL AND g.ip_long = INET_ATON(t.ip_addr)');
23
        $this->addSql('ALTER TABLE tracking ADD CONSTRAINT FK_A87C621C28F0F5E7 FOREIGN KEY (ip_long) REFERENCES geo_location (ip_long) ON DELETE SET NULL');
24
        $this->addSql('CREATE INDEX IDX_A87C621C28F0F5E7 ON tracking (ip_long)');
25
        $this->addSql("UPDATE tracking_archive AS t, geo_location AS g SET t.ip_long = g.ip_long WHERE t.ip_addr IS NOT NULL AND REGEXP_LIKE(t.ip_addr, '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$') AND g.ip_long = INET_ATON(t.ip_addr)");
26
    }
27

28
    public 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 tracking DROP FOREIGN KEY FK_A87C621C28F0F5E7');
34
        $this->addSql('DROP INDEX IDX_A87C621C28F0F5E7 ON tracking');
35
        $this->addSql('ALTER TABLE tracking DROP ip_long');
36
        $this->addSql('ALTER TABLE tracking_archive DROP ip_long');
37
    }
38
}
39

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

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

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

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