zend-blog-3-backend

Форк
0
/
Version20230616135557.php 
45 строк · 2.2 Кб
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 Version20230616135557 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 geo_location ADD ip_long INT UNSIGNED NOT NULL AFTER id, CHANGE city_id city_id INT DEFAULT NULL');
21
        $this->addSql('UPDATE geo_location SET ip_long = INET_ATON(ip_addr)');
22
        $this->addSql('ALTER TABLE comments DROP FOREIGN KEY FK_5F9E962AC34F22E');
23
        $this->addSql('DROP INDEX IDX_5F9E962AC34F22E ON comments');
24
        $this->addSql('ALTER TABLE comments DROP geo_location_id');
25
        $this->addSql('ALTER TABLE geo_location MODIFY id INT NOT NULL');
26
        $this->addSql('ALTER TABLE geo_location DROP PRIMARY KEY');
27
        $this->addSql('ALTER TABLE geo_location CHANGE id id INT NOT NULL');
28
        $this->addSql('ALTER TABLE geo_location ADD PRIMARY KEY (ip_long)');
29
        $this->addSql('ALTER TABLE geo_location DROP id');
30
    }
31

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

37
        $this->addSql('ALTER TABLE geo_location ADD id INT NOT NULL');
38
        $this->addSql('ALTER TABLE geo_location DROP PRIMARY KEY');
39
        $this->addSql('ALTER TABLE geo_location ADD PRIMARY KEY (id)');
40
        $this->addSql('ALTER TABLE comments ADD geo_location_id INT DEFAULT NULL');
41
        $this->addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962AC34F22E FOREIGN KEY (geo_location_id) REFERENCES geo_location (id) ON UPDATE NO ACTION ON DELETE SET NULL');
42
        $this->addSql('CREATE INDEX IDX_5F9E962AC34F22E ON comments (geo_location_id)');
43
        $this->addSql('ALTER TABLE geo_location DROP ip_long, CHANGE city_id city_id INT NOT NULL');
44
    }
45
}
46

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

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

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

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