From f7879f425f4e79d378a7d73d9df1238834cf4b54 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 17 Nov 2014 13:11:09 +0200 Subject: [PATCH] added 'indexes' section in entityDefs --- application/Espo/Core/Utils/Database/Orm/Converter.php | 4 ++++ .../Espo/Core/Utils/Database/Schema/Converter.php | 10 ++++++++-- application/Espo/Core/Utils/Database/Schema/Schema.php | 2 +- .../Crm/Resources/metadata/entityDefs/Account.json | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index d7b38bdf00..73dee61462 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -151,6 +151,10 @@ class Converter ), ); + if (isset($entityMeta['indexes'])) { + $ormMeta[$entityName]['indexes'] = $entityMeta['indexes']; + } + $ormMeta[$entityName]['fields'] = $this->convertFields($entityName, $entityMeta); $convertedLinks = $this->convertLinks($entityName, $entityMeta, $ormMeta); diff --git a/application/Espo/Core/Utils/Database/Schema/Converter.php b/application/Espo/Core/Utils/Database/Schema/Converter.php index f6d44f1dea..a9192d98eb 100644 --- a/application/Espo/Core/Utils/Database/Schema/Converter.php +++ b/application/Espo/Core/Utils/Database/Schema/Converter.php @@ -162,9 +162,15 @@ class Converter } $tables[$entityName]->setPrimaryKey($primaryColumns); + + //add indexes + if (isset($entityParams['indexes']) && is_array($entityParams['indexes'])) { + $indexList = array_merge($indexList, $entityParams['indexes']); + } if (!empty($indexList)) { - foreach($indexList as $indexItem) { - $tables[$entityName]->addIndex($indexItem); + foreach($indexList as $indexName => $indexItem) { + $tableIndexName = is_string($indexName) ? $indexName : null; + $tables[$entityName]->addIndex($indexItem, $tableIndexName); } } diff --git a/application/Espo/Core/Utils/Database/Schema/Schema.php b/application/Espo/Core/Utils/Database/Schema/Schema.php index 3a4eddebce..43f0f0cc18 100644 --- a/application/Espo/Core/Utils/Database/Schema/Schema.php +++ b/application/Espo/Core/Utils/Database/Schema/Schema.php @@ -198,7 +198,7 @@ class Schema $result = true; $connection = $this->getConnection(); foreach ($queries as $sql) { - $GLOBALS['log']->debug('SCHEMA, Execute Query: '.$sql); + $GLOBALS['log']->info('SCHEMA, Execute Query: '.$sql); try { $result &= (bool) $connection->executeQuery($sql); } catch (\Exception $e) { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json index 0fd4e4a863..e88a556ab6 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json @@ -162,5 +162,8 @@ "collection": { "sortBy": "name", "asc": true + }, + "indexes": { + "name": ["name"] } }