forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mautic#1213 from acquia/MAUT-5072
Segments are very slow to build
- Loading branch information
1 parent
e0ffc1c
commit 16e965e
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |