Added 'dbType' => 'longtext' for text fields

This commit is contained in:
Taras Machyshyn
2020-05-01 14:29:28 +03:00
parent 05888ae2c3
commit bf131b7a0e
7 changed files with 112 additions and 27 deletions
@@ -29,7 +29,7 @@
namespace Espo\Core\Utils\Database\DBAL\FieldTypes;
class JsonArrayType extends \Doctrine\DBAL\Types\TextType
class JsonArrayType extends TextType
{
const JSON_ARRAY = 'jsonArray';
@@ -37,10 +37,4 @@ class JsonArrayType extends \Doctrine\DBAL\Types\TextType
{
return self::JSON_ARRAY;
}
public static function getDbTypeName()
{
return 'TEXT';
}
}
@@ -29,7 +29,7 @@
namespace Espo\Core\Utils\Database\DBAL\FieldTypes;
class JsonObjectType extends \Doctrine\DBAL\Types\TextType
class JsonObjectType extends TextType
{
const JSON_OBJECT = 'jsonObject';
@@ -37,10 +37,4 @@ class JsonObjectType extends \Doctrine\DBAL\Types\TextType
{
return self::JSON_OBJECT;
}
public static function getDbTypeName()
{
return 'TEXT';
}
}
@@ -0,0 +1,52 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://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 General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Database\DBAL\FieldTypes;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class LongtextType extends TextType
{
const LONGTEXT = 'longtext';
public function getName()
{
return self::LONGTEXT;
}
public static function getDbTypeName()
{
return 'longtext';
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'LONGTEXT';
}
}
@@ -0,0 +1,45 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://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 General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Database\DBAL\FieldTypes;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class TextType extends \Doctrine\DBAL\Types\TextType
{
public static function getDbTypeName()
{
return 'mediumtext';
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'MEDIUMTEXT';
}
}
@@ -39,6 +39,7 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator
public function diffColumn(Column $column1, Column $column2)
{
$changedProperties = array();
if ( $column1->getType() != $column2->getType() ) {
//espo: fix problem with executing query for custom types
@@ -82,15 +83,6 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator
}
}
if ($column1->getType() instanceof \Doctrine\DBAL\Types\TextType) {
$length1 = $column1->getLength() ?: 16777215/* mediumtext length*/;
$length2 = $column2->getLength() ?: 16777215;
if ($length1 != -1 && $length2 != -1 && $length2 > $length1) {
$changedProperties[] = 'length';
}
}
if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
if (($column1->getPrecision()?:10) != ($column2->getPrecision()?:10)) {
$changedProperties[] = 'precision';
@@ -124,7 +116,7 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator
$changedProperties = array_merge($changedProperties, $diffKeys);
/** Espo: do not change a field length while changing other parameters */
/** Espo: do not change a field length downwards */
if (!empty($changedProperties) && !in_array('length', $changedProperties) && $column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
$length1 = $column1->getLength() ?: 255;
$length2 = $column2->getLength() ?: 255;
@@ -134,6 +126,15 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator
$column2->setLength($length1);
}
}
if (in_array('type', $changedProperties) && $column1->getType() instanceof \Doctrine\DBAL\Types\TextType && isset($column1DbTypeName) && isset($column2DbTypeName)) {
$constName1 = '\Espo\Core\Utils\Database\DBAL\Platforms\MySqlPlatform::LENGTH_LIMIT_' . strtoupper($column1DbTypeName);
$constName2 = '\Espo\Core\Utils\Database\DBAL\Platforms\MySqlPlatform::LENGTH_LIMIT_' . strtoupper($column2DbTypeName);
if (defined($constName1) && defined($constName2) && constant($constName1) >= constant($constName2)) {
$changedProperties = array_diff($changedProperties, ['type']);
}
}
/** Espo: end */
return $changedProperties;
@@ -209,7 +209,7 @@ class MySqlSchemaManager extends \Doctrine\DBAL\Schema\MySqlSchemaManager
case 'text':
case 'mediumtext':
case 'longtext':
$length = $this->_platform->getClobTypeLength($dbType);
$length = null;
break;
/* Espo: end */
}
@@ -46,8 +46,7 @@ return [
'type' => 'id',
],
'data' => [
'type' => 'text',
'len' => 16777216,
'type' => 'text'
]
]
],