migrations/Version20190913141126.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 Version20190913141126 extends AbstractMultiPlatformMigration
  28. {
  29.     public function getDescription(): string
  30.     {
  31.         return '';
  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 `groups` ADD perms_parts_category SMALLINT NOT NULL, ADD perms_parts_minamount SMALLINT NOT NULL, ADD perms_parts_lots SMALLINT NOT NULL, ADD perms_parts_tags SMALLINT NOT NULL, ADD perms_parts_unit SMALLINT NOT NULL, ADD perms_parts_mass SMALLINT NOT NULL, ADD perms_parts_status SMALLINT NOT NULL, ADD perms_parts_mpn SMALLINT NOT NULL, ADD perms_currencies INT NOT NULL, ADD perms_measurement_units INT NOT NULL, DROP perms_parts_instock, DROP perms_parts_mininstock, DROP perms_parts_storelocation');
  38.         $this->addSql('ALTER TABLE users ADD currency_id INT DEFAULT NULL, ADD settings LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', ADD perms_parts_category SMALLINT NOT NULL, ADD perms_parts_minamount SMALLINT NOT NULL, ADD perms_parts_lots SMALLINT NOT NULL, ADD perms_parts_tags SMALLINT NOT NULL, ADD perms_parts_unit SMALLINT NOT NULL, ADD perms_parts_mass SMALLINT NOT NULL, ADD perms_parts_status SMALLINT NOT NULL, ADD perms_parts_mpn SMALLINT NOT NULL, ADD perms_currencies INT NOT NULL, ADD perms_measurement_units INT NOT NULL, DROP config_currency, DROP perms_parts_instock, DROP perms_parts_mininstock, DROP perms_parts_storelocation');
  39.         $this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E938248176 FOREIGN KEY (currency_id) REFERENCES currencies (id)');
  40.         $this->addSql('CREATE INDEX IDX_1483A5E938248176 ON users (currency_id)');
  41.         //Set some default permissions for the groups
  42.         $sql 'UPDATE `groups`
  43.         SET perms_parts_category = 9, perms_parts_minamount = 9, perms_parts_lots = 169, perms_parts_tags= 9,
  44.             perms_parts_unit = 9, perms_parts_mass = 9, perms_parts_status = 9, perms_parts_mpn = 9,
  45.             perms_currencies = 9897, perms_measurement_units = 9897, perms_parts_attachements = 681,
  46.             perms_parts_orderdetails = 681, perms_parts_prices = 681
  47.         WHERE id = 2 AND name = "readonly";';
  48.         $this->addSql($sql);
  49.         $sql 'UPDATE `groups`
  50.         SET perms_parts_category = 5, perms_parts_minamount = 5, perms_parts_lots = 85, perms_parts_tags= 5,
  51.             perms_parts_unit = 5, perms_parts_mass = 5, perms_parts_status = 5, perms_parts_mpn = 5,
  52.             perms_currencies = 5461, perms_measurement_units = 5461, perms_parts_attachements = 341,
  53.             perms_parts_orderdetails = 341, perms_parts_prices = 341
  54.         WHERE (id = 1 AND name = "admins")
  55.             OR (id = 3 AND name = "users");        
  56.         ';
  57.         $this->addSql($sql);
  58.         $this->printPermissionUpdateMessage();
  59.     }
  60.     public function mySQLDown(Schema $schema): void
  61.     {
  62.         // this down() migration is auto-generated, please modify it to your needs
  63.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  64.         $this->addSql('ALTER TABLE `groups` ADD perms_parts_instock SMALLINT NOT NULL, ADD perms_parts_mininstock SMALLINT NOT NULL, ADD perms_parts_storelocation SMALLINT NOT NULL, DROP perms_parts_category, DROP perms_parts_minamount, DROP perms_parts_lots, DROP perms_parts_tags, DROP perms_parts_unit, DROP perms_parts_mass, DROP perms_parts_status, DROP perms_parts_mpn, DROP perms_currencies, DROP perms_measurement_units');
  65.         $this->addSql('ALTER TABLE `users` DROP FOREIGN KEY FK_1483A5E938248176');
  66.         $this->addSql('DROP INDEX IDX_1483A5E938248176 ON `users`');
  67.         $this->addSql('ALTER TABLE `users` ADD config_currency VARCHAR(255) NOT NULL COLLATE utf8_general_ci, ADD perms_parts_instock SMALLINT NOT NULL, ADD perms_parts_mininstock SMALLINT NOT NULL, ADD perms_parts_storelocation SMALLINT NOT NULL, DROP currency_id, DROP settings, DROP perms_parts_category, DROP perms_parts_minamount, DROP perms_parts_lots, DROP perms_parts_tags, DROP perms_parts_unit, DROP perms_parts_mass, DROP perms_parts_status, DROP perms_parts_mpn, DROP perms_currencies, DROP perms_measurement_units');
  68.     }
  69.     public function sqLiteUp(Schema $schema): void
  70.     {
  71.         $this->warnIf(true"Migration not needed for SQLite. Skipping...");
  72.     }
  73.     public function sqLiteDown(Schema $schema): void
  74.     {
  75.         $this->warnIf(true"Migration not needed for SQLite. Skipping...");
  76.     }
  77. }