Skip to content

Commit

Permalink
Merge pull request mautic#1213 from acquia/MAUT-5072
Browse files Browse the repository at this point in the history
Segments are very slow to build
  • Loading branch information
anton-vlasenko authored and escopecz committed Feb 23, 2024
1 parent e0ffc1c commit 16e965e
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions app/migrations/Version20210112162046.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/*
* @copyright 2020 Mautic Contributors. All rights reserved.
* @author Mautic
* @link https://mautic.org
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Mautic\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;

final class Version20210112162046 extends AbstractMauticMigration
{
private const TABLE_NAME = 'sync_object_mapping';
private const INDEX_NAME = 'integration_integration_object_name_last_sync_date';

public function preUp(Schema $schema): void
{
$this->skipIf(
$this->indexExists($schema),
sprintf('Index `%s` already exists. Skipping the migration', static::INDEX_NAME)
);
}

public function up(Schema $schema): void
{
$this->addSql(sprintf(
'ALTER TABLE `%s` ADD INDEX `%s` (`integration`, `internal_object_name`, `last_sync_date`);',
$this->getTableName(),
static::INDEX_NAME
));
}

public function preDown(Schema $schema): void
{
$this->skipIf(
!$this->indexExists($schema),
sprintf('Index `%s` doesn\'t exist. Skipping reverting the migration', static::INDEX_NAME)
);
}

public function down(Schema $schema): void
{
$this->addSql(sprintf(
'ALTER TABLE `%s` DROP INDEX `%s`;',
$this->getTableName(),
static::INDEX_NAME
));
}

private function getTableName(): string
{
return $this->prefix.static::TABLE_NAME;
}

private function indexExists(Schema $schema): bool
{
return $schema->getTable($this->getTableName())->hasIndex(static::INDEX_NAME);
}
}

0 comments on commit 16e965e

Please sign in to comment.