zend-blog-3-backend
45 строк · 2.2 Кб
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 Version20230616135557 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('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
32public function down(Schema $schema): void33{34// this down() migration is auto-generated, please modify it to your needs35$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