migrations/Version20200126191823.php line 1

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
  4.  *
  5.  * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU Affero General Public License as published
  9.  * by the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU Affero General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Affero General Public License
  18.  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  19.  */
  20. declare(strict_types=1);
  21. namespace DoctrineMigrations;
  22. use App\Migration\AbstractMultiPlatformMigration;
  23. use Doctrine\DBAL\Schema\Schema;
  24. /**
  25.  * Auto-generated Migration: Please modify to your needs!
  26.  */
  27. final class Version20200126191823 extends AbstractMultiPlatformMigration
  28. {
  29.     public function getDescription(): string
  30.     {
  31.         return 'Improve the schema of the log table';
  32.     }
  33.     public function mySQLUp(Schema $schema): void
  34.     {
  35.         // this up() migration is auto-generated, please modify it to your needs
  36.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  37.         $this->addSql('ALTER TABLE log CHANGE datetime datetime DATETIME NOT NULL, CHANGE level level TINYINT, CHANGE extra extra LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\'');
  38.         $this->addSql('DROP INDEX id_user ON log');
  39.         $this->addSql('ALTER TABLE log ADD CONSTRAINT FK_8F3F68C56B3CA4B FOREIGN KEY (id_user) REFERENCES `users` (id)');
  40.         $this->addSql('CREATE INDEX IDX_8F3F68C56B3CA4B ON log (id_user)');
  41.     }
  42.     public function mySQLDown(Schema $schema): void
  43.     {
  44.         // this down() migration is auto-generated, please modify it to your needs
  45.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  46.         $this->addSql('ALTER TABLE log DROP FOREIGN KEY FK_8F3F68C56B3CA4B');
  47.         $this->addSql('ALTER TABLE log DROP FOREIGN KEY FK_8F3F68C56B3CA4B');
  48.         $this->addSql('ALTER TABLE log CHANGE datetime datetime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE level level TINYINT(1) NOT NULL, CHANGE extra extra MEDIUMTEXT CHARACTER SET utf8 NOT NULL COLLATE `utf8_general_ci`');
  49.         $this->addSql('DROP INDEX idx_8f3f68c56b3ca4b ON log');
  50.         $this->addSql('CREATE INDEX id_user ON log (id_user)');
  51.         $this->addSql('ALTER TABLE log ADD CONSTRAINT FK_8F3F68C56B3CA4B FOREIGN KEY (id_user) REFERENCES `users` (id)');
  52.     }
  53.     public function sqLiteUp(Schema $schema): void
  54.     {
  55.         $this->warnIf(true"Migration not needed for SQLite. Skipping...");
  56.     }
  57.     public function sqLiteDown(Schema $schema): void
  58.     {
  59.         $this->warnIf(true"Migration not needed for SQLite. Skipping...");
  60.     }
  61. }