vendor/pimcore/pimcore/bundles/CoreBundle/Migrations/Version20230307135459.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Bundle\CoreBundle\Migrations;
  16. use Doctrine\DBAL\Schema\Schema;
  17. use Doctrine\Migrations\AbstractMigration;
  18. use Pimcore\Model\DataObject\Concrete\Dao\InheritanceHelper;
  19. final class Version20230307135459 extends AbstractMigration
  20. {
  21.     protected string $fieldname 'fieldname';
  22.     public function getDescription(): string
  23.     {
  24.         return 'Add fieldname index to object_relations_ tables';
  25.     }
  26.     public function up(Schema $schema): void
  27.     {
  28.         foreach ($schema->getTables() as $table) {
  29.             if (str_starts_with($table->getName(), InheritanceHelper::RELATION_TABLE) && !$table->hasIndex($this->fieldname)) {
  30.                 $table->addIndex([$this->fieldname], $this->fieldname);
  31.             }
  32.         }
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         foreach ($schema->getTables() as $table) {
  37.             if (str_starts_with($table->getName(), InheritanceHelper::RELATION_TABLE) && $table->hasIndex($this->fieldname)) {
  38.                 $table->dropIndex($this->fieldname);
  39.             }
  40.         }
  41.     }
  42. }