EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Early rebuild
Yuriia2a49ddabab1
diff --git a/application/Espo/Core/Utils/Database/Schema/EarlyRebuildAction.php b/application/Espo/Core/Utils/Database/Schema/EarlyRebuildAction.phpnew file mode 100644index 0000000000..be9e14e2b4--- /dev/null+++ b/application/Espo/Core/Utils/Database/Schema/EarlyRebuildAction.php@@ -0,0 +1,38 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Utils\Database\Schema;++/**+ * @since 10.1.0.+ */+interface EarlyRebuildAction+{+ public function process(): void;+}diff --git a/application/Espo/Core/Utils/Database/Schema/MetadataProvider.php b/application/Espo/Core/Utils/Database/Schema/MetadataProvider.phpindex 8fb87809f4..bcde33916c 100644--- a/application/Espo/Core/Utils/Database/Schema/MetadataProvider.php+++ b/application/Espo/Core/Utils/Database/Schema/MetadataProvider.php@@ -45,6 +45,16 @@ class MetadataProviderreturn $this->configDataProvider->getPlatform();}+ /**+ * @return class-string<EarlyRebuildAction>[]+ */+ public function getEarlyRebuildActionClassNameList(): array+ {+ /** @var class-string<EarlyRebuildAction>[] */+ return $this->metadata+ ->get(['app', 'databasePlatforms', $this->getPlatform(), 'earlyRebuildActionClassNameList']) ?? [];+ }+/*** @return class-string<RebuildAction>[]*/diff --git a/application/Espo/Core/Utils/Database/Schema/RebuildActions/Postgresql/MigrateSequences.php b/application/Espo/Core/Utils/Database/Schema/RebuildActions/Postgresql/MigrateSequences.phpindex a4be6bd037..3dee155807 100644--- a/application/Espo/Core/Utils/Database/Schema/RebuildActions/Postgresql/MigrateSequences.php+++ b/application/Espo/Core/Utils/Database/Schema/RebuildActions/Postgresql/MigrateSequences.php@@ -30,23 +30,22 @@namespace Espo\Core\Utils\Database\Schema\RebuildActions\Postgresql;use Doctrine\DBAL\Exception;-use Doctrine\DBAL\Schema\Schema as DbalSchema;use Espo\Core\Utils\Config;use Espo\Core\Utils\Database\Helper;-use Espo\Core\Utils\Database\Schema\RebuildAction;+use Espo\Core\Utils\Database\Schema\EarlyRebuildAction;use RuntimeException;/*** @noinspection PhpUnused*/-class MigrateSequences implements RebuildAction+class MigrateSequences implements EarlyRebuildAction{public function __construct(private Config\SystemConfig $config,private Helper $helper,) {}- public function process(DbalSchema $oldSchema, DbalSchema $newSchema): void+ public function process(): void{$version = $this->config->getVersion();diff --git a/application/Espo/Core/Utils/Database/Schema/SchemaManager.php b/application/Espo/Core/Utils/Database/Schema/SchemaManager.phpindex e2980a6600..565743ad51 100644--- a/application/Espo/Core/Utils/Database/Schema/SchemaManager.php+++ b/application/Espo/Core/Utils/Database/Schema/SchemaManager.php@@ -157,6 +157,12 @@ class SchemaManager*/public function rebuild(?array $entityTypeList = null, string $mode = RebuildMode::SOFT): bool{+ try {+ $this->processEarlyRebuildActions();+ } catch (Throwable $e) {+ throw new RuntimeException("Rebuild database early-rebuild error.", previous: $e);+ }+$fromSchema = $this->introspectSchema();$schema = $this->builder->build($this->ormMetadataData->getData(), $entityTypeList);@@ -261,6 +267,19 @@ class SchemaManagerreturn $this->getPlatform()->getAlterSchemaSQL($diff);}+ private function processEarlyRebuildActions(): void+ {+ $binding = BindingContainerBuilder::create()+ ->bindInstance(Helper::class, $this->helper)+ ->build();++ foreach ($this->metadataProvider->getEarlyRebuildActionClassNameList() as $className) {+ $action = $this->injectableFactory->createWithBinding($className, $binding);++ $action->process();+ }+ }+private function processPreRebuildActions(Schema $actualSchema, Schema $schema): void{$binding = BindingContainerBuilder::create()diff --git a/application/Espo/Resources/metadata/app/databasePlatforms.json b/application/Espo/Resources/metadata/app/databasePlatforms.jsonindex 9b1fae5f87..d1abde463d 100644--- a/application/Espo/Resources/metadata/app/databasePlatforms.json+++ b/application/Espo/Resources/metadata/app/databasePlatforms.json@@ -22,7 +22,7 @@"dbalTypeClassNameMap": {"uuid": "Espo\\Core\\Utils\\Database\\Dbal\\Types\\UuidType"},- "preRebuildActionClassNameList": [+ "earlyRebuildActionClassNameList": ["Espo\\Core\\Utils\\Database\\Schema\\RebuildActions\\Postgresql\\MigrateSequences"]}diff --git a/schema/metadata/app/databasePlatforms.json b/schema/metadata/app/databasePlatforms.jsonindex bff8dd4034..38bd7b29c4 100644--- a/schema/metadata/app/databasePlatforms.json+++ b/schema/metadata/app/databasePlatforms.json@@ -31,6 +31,16 @@"type": "string","description": "Should implement Espo\\Core\\Utils\\Database\\Schema\\ColumnPreparator."},+ "earlyRebuildActionClassNameList": {+ "type": "array",+ "description": "Early-rebuild actions. Should implement Espo\\Core\\Utils\\Database\\Schema\\EarlyRebuildAction. As of v10.1.",+ "items": {+ "anyOf": [+ {"enum": ["__APPEND__"]},+ {"type": "string"}+ ]+ }+ },"preRebuildActionClassNameList": {"type": "array","description": "Pre-rebuild actions. Should implement Espo\\Core\\Utils\\Database\\Schema\\RebuildAction.",