Skip to content

Commit 7503f4a

Browse files
committed
Merge remote-tracking branch 'origin/AC-11654' into spartans_pr_15042024
2 parents 775d7d3 + 18a8049 commit 7503f4a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ public function __construct(
6767

6868
/**
6969
* @inheritdoc
70+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7071
*/
71-
public function build(Schema $schema)
72+
public function build(Schema $schema, $tablesWithJsonTypeField = [])
7273
{
7374
foreach ($this->sharding->getResources() as $resource) {
7475
foreach ($this->dbSchemaReader->readTables($resource) as $tableName) {
@@ -95,9 +96,16 @@ public function build(Schema $schema)
9596
'collation' => $tableOptions['collation']
9697
]
9798
);
99+
$isJsonType = false;
100+
if (count($tablesWithJsonTypeField) > 0 && isset($tablesWithJsonTypeField[$tableName])) {
101+
$isJsonType = true;
102+
}
98103

99104
// Process columns
100105
foreach ($columnsData as $columnData) {
106+
if ($isJsonType && $tablesWithJsonTypeField[$tableName] == $columnData['name']) {
107+
$columnData['type'] = 'json';
108+
}
101109
$columnData['table'] = $table;
102110
$column = $this->elementFactory->create($columnData['type'], $columnData);
103111
$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);
75+
$schema = $this->dbSchemaBuilder->build($schema, $tablesWithJsonTypeField);
6776
return $schema;
6877
}
6978

0 commit comments

Comments
 (0)