Skip to content

EspoCRM – Open Source CRM Application

Fix DBAL bug diff

Yurii70b6bd74853d
diff --git a/application/Espo/Core/Utils/Database/Schema/ColumnPreparators/MysqlColumnPreparator.php b/application/Espo/Core/Utils/Database/Schema/ColumnPreparators/MysqlColumnPreparator.php
index 9265feb3b5..f401974845 100644
--- a/application/Espo/Core/Utils/Database/Schema/ColumnPreparators/MysqlColumnPreparator.php
+++ b/application/Espo/Core/Utils/Database/Schema/ColumnPreparators/MysqlColumnPreparator.php
@@ -63,6 +63,7 @@ class MysqlColumnPreparator implements ColumnPreparator
private const int DEFAULT_STRING_MAX_LENGTH = 255;
private const int DEFAULT_PRECISION = 13;
private const int DEFAULT_SCALE = 4;
+ private const int DEFAULT_FLOAT_PRECISION = 22;
/** @var string[] */
private array $mediumTextTypeList = [
@@ -133,6 +134,10 @@ class MysqlColumnPreparator implements ColumnPreparator
$scale ??= self::DEFAULT_SCALE;
}
+ if ($columnType === Types::FLOAT) {
+ $precision = self::DEFAULT_FLOAT_PRECISION;
+ }
+
if ($precision !== null) {
$column = $column->withPrecision($precision);
}
@@ -189,7 +194,9 @@ class MysqlColumnPreparator implements ColumnPreparator
LongtextType::NAME,
])
) {
- return $column;
+ return $column
+ ->withCollation(null)
+ ->withCharset(null);
}
$collation = $binary ?
diff --git a/application/Espo/Core/Utils/Database/Schema/DiffModifier.php b/application/Espo/Core/Utils/Database/Schema/DiffModifier.php
index b42e57534e..6a185d6c9a 100644
--- a/application/Espo/Core/Utils/Database/Schema/DiffModifier.php
+++ b/application/Espo/Core/Utils/Database/Schema/DiffModifier.php
@@ -138,6 +138,12 @@ class DiffModifier
foreach ($tableDiff->getChangedColumns() as $name => $columnDiff) {
$newColumnDiff = $columnDiff;
+ $this->fixPlatformOptions($columnDiff);
+
+ if ($columnDiff->countChangedProperties() === 0) {
+ continue;
+ }
+
if (!$isHard) {
$this->amendColumnDiffLength($columnDiff);
$this->amendColumnDiffTextType($columnDiff);
@@ -315,6 +321,28 @@ class DiffModifier
return true;
}
+ /**
+ * Fixes the DBAL's bug that platform options are detected as changed for FLOAT columns.
+ */
+ private function fixPlatformOptions(ColumnDiff $columnDiff): void
+ {
+ $oldColumn = $columnDiff->getOldColumn();
+ $newColumn = $columnDiff->getNewColumn();
+
+ if (!$columnDiff->hasPlatformOptionsChanged()) {
+ return;
+ }
+
+ if (
+ $oldColumn->getCollation() === null &&
+ $newColumn->getCollation() === null &&
+ $oldColumn->getCharset() === null &&
+ $newColumn->getCharset() === null
+ ) {
+ $oldColumn->setPlatformOptions([]);
+ }
+ }
+
private function moveRemovedAutoincrementColumnToChanged(TableDiff $tableDiff, Column $column): ?TableDiff
{
if (!$column->getAutoincrement()) {