vendor/pimcore/pimcore/bundles/CoreBundle/Migrations/Version20211221152344.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. final class Version20211221152344 extends AbstractMigration
  19. {
  20.     public function getDescription(): string
  21.     {
  22.         return '';
  23.     }
  24.     public function up(Schema $schema): void
  25.     {
  26.         //disable foreign key checks
  27.         $this->addSql('SET foreign_key_checks = 0');
  28.         $this->addSql('ALTER TABLE `assets_metadata` CHANGE `cid` `cid` int(11) unsigned NOT NULL;');
  29.         if (!$schema->getTable('assets_metadata')->hasForeignKey('fk_assets_metadata_assets')) {
  30.             $this->addSql(
  31.                 'ALTER TABLE `assets_metadata`
  32.                 ADD CONSTRAINT `fk_assets_metadata_assets`
  33.                 FOREIGN KEY (`cid`)
  34.                 REFERENCES `assets` (`id`)
  35.                 ON UPDATE NO ACTION
  36.                 ON DELETE CASCADE;'
  37.             );
  38.         }
  39.         //enable foreign key checks
  40.         $this->addSql('SET foreign_key_checks = 1');
  41.     }
  42.     public function down(Schema $schema): void
  43.     {
  44.         if ($schema->getTable('assets_metadata')->hasForeignKey('fk_assets_metadata_assets')) {
  45.             $this->addSql('ALTER TABLE `assets_metadata` DROP FOREIGN KEY `fk_assets_metadata_assets`;');
  46.         }
  47.         $this->addSql('ALTER TABLE `assets_metadata` CHANGE `cid` `cid` int(11) NOT NULL;');
  48.     }
  49. }