Skip to content

Commit 2eb10d6

Browse files
committed
AC-11654::Integration test failing testDbSchemaUpToDate due to JSON column type
1 parent af6d22a commit 2eb10d6

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/DbSchemaReaderInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ public function readConstraints($tableName, $resource);
3838
*
3939
* @param string $tableName
4040
* @param string $resource
41-
* @param object $declarativeSchema
4241
* @return array
4342
*/
44-
public function readColumns($tableName, $resource, $declarativeSchema);
43+
public function readColumns($tableName, $resource);
4544

4645
/**
4746
* Show table options like engine, partitioning, etc.

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaReader.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DbSchemaReader implements DbSchemaReaderInterface
2121
/**
2222
* Table type in information_schema.TABLES which allows to identify only tables and ignore views
2323
*/
24-
public const MYSQL_TABLE_TYPE = 'BASE TABLE';
24+
const MYSQL_TABLE_TYPE = 'BASE TABLE';
2525

2626
/**
2727
* @var ResourceConnection
@@ -81,10 +81,9 @@ public function getTableOptions($tableName, $resource)
8181
*
8282
* @param string $tableName
8383
* @param string $resource
84-
* @param array $tablesWithJsonTypeField
8584
* @return array
8685
*/
87-
public function readColumns($tableName, $resource, $tablesWithJsonTypeField = [])
86+
public function readColumns($tableName, $resource)
8887
{
8988
$columns = [];
9089
$adapter = $this->resourceConnection->getConnection($resource);
@@ -109,10 +108,6 @@ public function readColumns($tableName, $resource, $tablesWithJsonTypeField = []
109108
$columnsDefinition = $adapter->fetchAssoc($stmt);
110109

111110
foreach ($columnsDefinition as $columnDefinition) {
112-
if (count($tablesWithJsonTypeField) > 0 && isset($tablesWithJsonTypeField[$tableName])
113-
&& $tablesWithJsonTypeField[$tableName] == $columnDefinition['name']) {
114-
$columnDefinition['type'] = 'json';
115-
}
116111
$column = $this->definitionAggregator->fromDefinition($columnDefinition);
117112
$columns[$column['name']] = $column;
118113
}

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,17 @@ public function __construct(
6767

6868
/**
6969
* @inheritdoc
70-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7170
*/
72-
public function build(Schema $schema, $declarativeSchema = null)
71+
public function build(Schema $schema, $tablesWithJsonTypeField = [])
7372
{
74-
$tablesWithJsonTypeField = [];
75-
if ($declarativeSchema != null) {
76-
foreach ($declarativeSchema->getTables() as $table) {
77-
foreach ($table->getColumns() as $column) {
78-
if ($column->getType() == 'json') {
79-
$tablesWithJsonTypeField[$table->getName()] = $column->getName();
80-
}
81-
}
82-
}
83-
}
8473
foreach ($this->sharding->getResources() as $resource) {
8574
foreach ($this->dbSchemaReader->readTables($resource) as $tableName) {
8675
$columns = [];
8776
$indexes = [];
8877
$constraints = [];
8978

9079
$tableOptions = $this->dbSchemaReader->getTableOptions($tableName, $resource);
91-
$columnsData = $this->dbSchemaReader->readColumns($tableName, $resource, $tablesWithJsonTypeField);
80+
$columnsData = $this->dbSchemaReader->readColumns($tableName, $resource);
9281
$indexesData = $this->dbSchemaReader->readIndexes($tableName, $resource);
9382
$constrainsData = $this->dbSchemaReader->readConstraints($tableName, $resource);
9483

@@ -106,9 +95,16 @@ public function build(Schema $schema, $declarativeSchema = null)
10695
'collation' => $tableOptions['collation']
10796
]
10897
);
98+
$isJsonType = false;
99+
if (count($tablesWithJsonTypeField) > 0 && isset($tablesWithJsonTypeField[$tableName])) {
100+
$isJsonType = true;
101+
}
109102

110103
// Process columns
111104
foreach ($columnsData as $columnData) {
105+
if ($isJsonType && $tablesWithJsonTypeField[$tableName] == $columnData['name']) {
106+
$columnData['type'] = 'json';
107+
}
112108
$columnData['table'] = $table;
113109
$column = $this->elementFactory->create($columnData['type'], $columnData);
114110
$columns[$column->getName()] = $column;

lib/internal/Magento/Framework/Setup/Declaration/Schema/SchemaConfig.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ public function __construct(
6262
*/
6363
public function getDbConfig()
6464
{
65+
$declarativeSchema = $this->getDeclarationConfig();
66+
$tablesWithJsonTypeField = [];
67+
foreach ($declarativeSchema->getTables() as $table) {
68+
foreach ($table->getColumns() as $column) {
69+
if ($column->getType() == 'json') {
70+
$tablesWithJsonTypeField[$table->getName()] = $column->getName();
71+
}
72+
}
73+
}
6574
$schema = $this->schemaFactory->create();
66-
$schema = $this->dbSchemaBuilder->build($schema, $this->getDeclarationConfig());
75+
$schema = $this->dbSchemaBuilder->build($schema, $tablesWithJsonTypeField);
6776
return $schema;
6877
}
6978

0 commit comments

Comments
 (0)