DBAL: fixed a problem of changing text field type

This commit is contained in:
Taras Machyshyn
2018-12-21 18:15:10 +02:00
parent 65368519c7
commit d7fc389182
4 changed files with 38 additions and 2 deletions
@@ -29,7 +29,7 @@
namespace Espo\Core\Utils\Database\DBAL\FieldTypes;
class JsonArrayType extends \Doctrine\DBAL\Types\JsonArrayType
class JsonArrayType extends \Doctrine\DBAL\Types\TextType
{
const JSON_ARRAY = 'jsonArray';
@@ -29,7 +29,7 @@
namespace Espo\Core\Utils\Database\DBAL\FieldTypes;
class JsonObjectType extends \Doctrine\DBAL\Types\ObjectType
class JsonObjectType extends \Doctrine\DBAL\Types\TextType
{
const JSON_OBJECT = 'jsonObject';
@@ -38,6 +38,10 @@ use Doctrine\DBAL\Schema\Column;
class MySqlPlatform extends \Doctrine\DBAL\Platforms\MySqlPlatform
{
/* Espo */
const LENGTH_LIMIT_LONGTEXT = 4294967295;
/* Espo: end */
public function getAlterTableSQL(TableDiff $diff)
{
$columnSql = array();
@@ -453,6 +457,29 @@ class MySqlPlatform extends \Doctrine\DBAL\Platforms\MySqlPlatform
return 'MEDIUMTEXT';
}
/* Espo: fix a problem of changing text field type */
public function getClobTypeLength($type)
{
switch ($type) {
case 'tinytext':
return static::LENGTH_LIMIT_TINYTEXT;
break;
case 'text':
return static::LENGTH_LIMIT_TEXT;
break;
case 'mediumtext':
return static::LENGTH_LIMIT_MEDIUMTEXT;
break;
case 'longtext':
return static::LENGTH_LIMIT_LONGTEXT;
break;
}
}
/* Espo: end */
public function getColumnDeclarationListSQL(array $fields)
{
$queryFields = array();
@@ -203,6 +203,15 @@ class MySqlSchemaManager extends \Doctrine\DBAL\Schema\MySqlSchemaManager
case 'year':
$length = null;
break;
/* Espo: fix a problem of changing text field type */
case 'tinytext':
case 'text':
case 'mediumtext':
case 'longtext':
$length = $this->_platform->getClobTypeLength($dbType);
break;
/* Espo: end */
}
$length = ((int) $length == 0) ? null : (int) $length;