Skip to content

Commit a93380b

Browse files
author
Anna Bukatar
committed
ACP2E-2844: Issues after upgrading MariaDB to 10.5.1 or higher
1 parent a7e0370 commit a93380b

File tree

2 files changed

+89
-11
lines changed

2 files changed

+89
-11
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,13 +1812,8 @@ private function prepareColumnData(array $ddl): array
18121812
}
18131813
}
18141814

1815-
/**
1816-
* Starting from MariaDB 10.5.1 columns with old temporal formats are marked with a \/* mariadb-5.3 *\/
1817-
* comment in the output of SHOW CREATE TABLE, SHOW COLUMNS, DESCRIBE statements,
1818-
* as well as in the COLUMN_TYPE column of the INFORMATION_SCHEMA.COLUMNS Table.
1819-
*/
18201815
foreach ($ddl as $key => $columnData) {
1821-
$ddl[$key]['DATA_TYPE'] = str_replace(' /* mariadb-5.3 */', '', $columnData['DATA_TYPE']);
1816+
$ddl[$key]['DATA_TYPE'] = $this->sanitizeColumnDataType($columnData['DATA_TYPE']);
18221817
}
18231818

18241819
return $ddl;
@@ -1975,7 +1970,7 @@ public function modifyColumnByDdl($tableName, $columnName, $definition, $flushDa
19751970
protected function _getColumnTypeByDdl($column)
19761971
{
19771972
// phpstan:ignore
1978-
switch ($column['DATA_TYPE']) {
1973+
switch ($this->sanitizeColumnDataType($column['DATA_TYPE'])) {
19791974
case 'bool':
19801975
return Table::TYPE_BOOLEAN;
19811976
case 'tinytext':
@@ -2012,6 +2007,22 @@ protected function _getColumnTypeByDdl($column)
20122007
return null;
20132008
}
20142009

2010+
/**
2011+
* Remove old temporal format comment from column data type
2012+
*
2013+
* @param string $columnType
2014+
* @return string
2015+
*/
2016+
private function sanitizeColumnDataType(string $columnType): string
2017+
{
2018+
/**
2019+
* Starting from MariaDB 10.5.1 columns with old temporal formats are marked with a \/* mariadb-5.3 *\/
2020+
* comment in the output of SHOW CREATE TABLE, SHOW COLUMNS, DESCRIBE statements,
2021+
* as well as in the COLUMN_TYPE column of the INFORMATION_SCHEMA.COLUMNS Table.
2022+
*/
2023+
return str_replace(' /* mariadb-5.3 */', '', $columnType);
2024+
}
2025+
20152026
/**
20162027
* Change table storage engine
20172028
*
@@ -2584,6 +2595,8 @@ protected function _getColumnDefinition($options, $ddlType = null)
25842595
// detect and validate column type
25852596
if ($ddlType === null) {
25862597
$ddlType = $this->_getDdlType($options);
2598+
} else {
2599+
$ddlType = $this->sanitizeColumnDataType($ddlType);
25872600
}
25882601

25892602
if (empty($ddlType) || !isset($this->_ddlColumnTypes[$ddlType])) {
@@ -3225,7 +3238,7 @@ public function prepareColumnValue(array $column, $value)
32253238
return $value;
32263239
}
32273240

3228-
$column['DATA_TYPE'] = str_replace(' /* mariadb-5.3 */', '', $column['DATA_TYPE']);
3241+
$column['DATA_TYPE'] = $this->sanitizeColumnDataType($column['DATA_TYPE']);
32293242

32303243
// return original value if invalid column describe data
32313244
if (!isset($column['DATA_TYPE'])) {
@@ -3996,7 +4009,7 @@ protected function _getDdlType($options)
39964009
$ddlType = $options['COLUMN_TYPE'];
39974010
}
39984011

3999-
return $ddlType;
4012+
return $this->sanitizeColumnDataType($ddlType);
40004013
}
40014014

40024015
/**

lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo/MysqlTest.php

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,12 +854,12 @@ public function columnDataForTest(): array
854854

855855
/**
856856
* @param array $actual
857-
* @param mixed $expected
857+
* @param int|string|\Zend_Db_Expr $expected
858858
* @dataProvider columnDataAndValueForTest
859859
* @return void
860860
* @throws \ReflectionException
861861
*/
862-
public function testPrepareColumnValue(array $actual, mixed $expected)
862+
public function testPrepareColumnValue(array $actual, int|string|\Zend_Db_Expr $expected)
863863
{
864864
$adapter = $this->getMysqlPdoAdapterMock([]);
865865

@@ -886,6 +886,26 @@ public function columnDataAndValueForTest(): array
886886
],
887887
'expected' => 10
888888
],
889+
[
890+
'actual' => [
891+
[
892+
'DATA_TYPE' => 'datetime /* mariadb-5.3 */',
893+
'DEFAULT' => 'CURRENT_TIMESTAMP'
894+
],
895+
'null'
896+
],
897+
'expected' => new \Zend_Db_Expr('NULL')
898+
],
899+
[
900+
'actual' => [
901+
[
902+
'DATA_TYPE' => 'date /* mariadb-5.3 */',
903+
'DEFAULT' => ''
904+
],
905+
'null'
906+
],
907+
'expected' => new \Zend_Db_Expr('NULL')
908+
],
889909
[
890910
'actual' => [
891911
[
@@ -910,6 +930,51 @@ public function columnDataAndValueForTest(): array
910930
];
911931
}
912932

933+
/**
934+
* @param string $actual
935+
* @param string $expected
936+
* @dataProvider providerForSanitizeColumnDataType
937+
* @return void
938+
* @throws \ReflectionException
939+
*/
940+
public function testSanitizeColumnDataType(string $actual, string $expected)
941+
{
942+
$adapter = $this->getMysqlPdoAdapterMock([]);
943+
$result = $this->invokeModelMethod($adapter, 'sanitizeColumnDataType', [$actual]);
944+
$this->assertEquals($expected, $result);
945+
}
946+
947+
/**
948+
* Data provider for testSanitizeColumnDataType
949+
*
950+
* @return array[]
951+
*/
952+
public function providerForSanitizeColumnDataType()
953+
{
954+
return [
955+
[
956+
'actual' => 'int',
957+
'expected' => 'int'
958+
],
959+
[
960+
'actual' => 'varchar',
961+
'expected' => 'varchar'
962+
],
963+
[
964+
'actual' => 'datetime /* mariadb-5.3 */',
965+
'expected' => 'datetime'
966+
],
967+
[
968+
'actual' => 'date /* mariadb-5.3 */',
969+
'expected' => 'date'
970+
],
971+
[
972+
'actual' => 'timestamp /* mariadb-5.3 */',
973+
'expected' => 'timestamp'
974+
]
975+
];
976+
}
977+
913978
/**
914979
* @param string $method
915980
* @param array $parameters

0 commit comments

Comments
 (0)