zend-blog-3-backend
36 строк · 1.7 Кб
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Schema\Schema;
6use Doctrine\Migrations\AbstractMigration;
7
8/**
9* Auto-generated Migration: Please modify to your needs!
10*/
11class Version20150223224004 extends AbstractMigration
12{
13public function up(Schema $schema): void
14{
15// this up() migration is auto-generated, please modify it to your needs
16$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
17
18$this->addSql('DROP INDEX UNIQ_CDD78530C44967C5 ON tracking_agent');
19$this->addSql('ALTER TABLE tracking_agent ADD hash VARCHAR(32) NOT NULL AFTER user_agent, CHANGE user_agent user_agent TEXT NOT NULL');
20$this->addSql('UPDATE tracking_agent SET hash = MD5(user_agent)');
21$this->addSql('CREATE UNIQUE INDEX UNIQ_CDD78530D1B862B8 ON tracking_agent (hash)');
22$this->addSql('ALTER TABLE tracking ADD timestamp_created INT NOT NULL');
23$this->addSql('UPDATE tracking SET timestamp_created = UNIX_TIMESTAMP( time_created )');
24}
25
26public function down(Schema $schema): void
27{
28// this down() migration is auto-generated, please modify it to your needs
29$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
30
31$this->addSql('DROP INDEX UNIQ_CDD78530D1B862B8 ON tracking_agent');
32$this->addSql('ALTER TABLE tracking_agent DROP hash, CHANGE user_agent user_agent VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci');
33$this->addSql('CREATE UNIQUE INDEX UNIQ_CDD78530C44967C5 ON tracking_agent (user_agent)');
34$this->addSql('ALTER TABLE tracking DROP timestamp_created');
35}
36}
37