/
AddIndexes.php
43 lines (37 loc) · 1.21 KB
/
AddIndexes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Oro\Bundle\WebsiteSearchBundle\Migrations\Schema\v1_3;
use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
/**
* Indexes for performance optimization
*/
class AddIndexes implements Migration
{
/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
$this->addIndexes($schema, 'oro_website_search_decimal');
$this->addIndexes($schema, 'oro_website_search_integer');
$this->addIndexes($schema, 'oro_website_search_datetime');
$this->addIndexes($schema, 'oro_website_search_text');
}
/**
* @param Schema $schema
* @param string $tableName
*/
protected function addIndexes(Schema $schema, $tableName)
{
$table = $schema->getTable($tableName);
$fieldIndexName = $tableName . '_field_idx';
if (!$table->hasIndex($fieldIndexName)) {
$table->addIndex(['field'], $fieldIndexName);
}
$itemFieldIndexName = $tableName . '_item_field_idx';
if (!$table->hasIndex($itemFieldIndexName)) {
$table->addIndex(['item_id', 'field'], $itemFieldIndexName);
}
}
}