Skip to content

Commit 8917571

Browse files
committed
AC-11654::Integration test failing testDbSchemaUpToDate due to JSON column type
1 parent 7e0e558 commit 8917571

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

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

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

4546
/**
4647
* Show table options like engine, partitioning, etc.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ public function getTableOptions($tableName, $resource)
8181
*
8282
* @param string $tableName
8383
* @param string $resource
84+
* @param array $tablesWithJsonTypeField
8485
* @return array
8586
*/
86-
public function readColumns($tableName, $resource)
87+
public function readColumns($tableName, $resource, $tablesWithJsonTypeField = [])
8788
{
8889
$columns = [];
8990
$adapter = $this->resourceConnection->getConnection($resource);
@@ -108,6 +109,9 @@ public function readColumns($tableName, $resource)
108109
$columnsDefinition = $adapter->fetchAssoc($stmt);
109110

110111
foreach ($columnsDefinition as $columnDefinition) {
112+
if (count($tablesWithJsonTypeField) > 0 && isset($tablesWithJsonTypeField[$tableName]) && $tablesWithJsonTypeField[$tableName] == $columnDefinition['name']) {
113+
$columnDefinition['type'] = 'json';
114+
}
111115
$column = $this->definitionAggregator->fromDefinition($columnDefinition);
112116
$columns[$column['name']] = $column;
113117
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,26 @@ public function __construct(
6868
/**
6969
* @inheritdoc
7070
*/
71-
public function build(Schema $schema)
71+
public function build(Schema $schema, $declarativeSchema = null)
7272
{
73+
$tablesWithJsonTypeField = [];
74+
if($declarativeSchema != null) {
75+
foreach ($declarativeSchema->getTables() as $table) {
76+
foreach ($table->getColumns() as $column) {
77+
if ($column->getType() == 'json') {
78+
$tablesWithJsonTypeField[$table->getName()] = $column->getName();
79+
}
80+
}
81+
}
82+
}
7383
foreach ($this->sharding->getResources() as $resource) {
7484
foreach ($this->dbSchemaReader->readTables($resource) as $tableName) {
7585
$columns = [];
7686
$indexes = [];
7787
$constraints = [];
7888

7989
$tableOptions = $this->dbSchemaReader->getTableOptions($tableName, $resource);
80-
$columnsData = $this->dbSchemaReader->readColumns($tableName, $resource);
90+
$columnsData = $this->dbSchemaReader->readColumns($tableName, $resource, $tablesWithJsonTypeField);
8191
$indexesData = $this->dbSchemaReader->readIndexes($tableName, $resource);
8292
$constrainsData = $this->dbSchemaReader->readConstraints($tableName, $resource);
8393

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(
6363
public function getDbConfig()
6464
{
6565
$schema = $this->schemaFactory->create();
66-
$schema = $this->dbSchemaBuilder->build($schema);
66+
$schema = $this->dbSchemaBuilder->build($schema, $this->getDeclarationConfig());
6767
return $schema;
6868
}
6969

0 commit comments

Comments
 (0)