Skip to content

Commit 98fa3df

Browse files
committed
AC-11654::Integration test failing testDbSchemaUpToDate due to JSON column type
1 parent e794ee7 commit 98fa3df

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\Framework\Setup\Declaration\Schema\Dto\Schema;
1515
use Magento\Framework\Setup\Declaration\Schema\Dto\Table;
1616
use Magento\Framework\Setup\Declaration\Schema\Sharding;
17+
use Magento\Framework\Config\FileResolverByModule;
18+
use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite;
1719

1820
/**
1921
* This type of builder is responsible for converting ENTIRE data, that comes from db
@@ -49,35 +51,47 @@ class SchemaBuilder
4951
private $tables;
5052

5153
/**
52-
* declared tables.
53-
*
54-
* @var array
54+
* @var ReaderComposite
5555
*/
56-
private array $tablesWithJsonTypeField = [];
56+
private $readerComposite;
5757

5858
/**
5959
* Constructor.
6060
*
6161
* @param ElementFactory $elementFactory
6262
* @param DbSchemaReaderInterface $dbSchemaReader
6363
* @param Sharding $sharding
64+
* @param ReaderComposite $readerComposite
6465
*/
6566
public function __construct(
6667
ElementFactory $elementFactory,
6768
DbSchemaReaderInterface $dbSchemaReader,
68-
Sharding $sharding
69+
Sharding $sharding,
70+
ReaderComposite $readerComposite
6971
) {
7072
$this->elementFactory = $elementFactory;
7173
$this->dbSchemaReader = $dbSchemaReader;
7274
$this->sharding = $sharding;
75+
$this->readerComposite = $readerComposite;
7376
}
7477

7578
/**
7679
* @inheritdoc
7780
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
81+
* @SuppressWarnings(PHPMD.NPathComplexity)
7882
*/
7983
public function build(Schema $schema)
8084
{
85+
$data = $this->readerComposite->read(FileResolverByModule::ALL_MODULES);
86+
$tablesWithJsonTypeField = [];
87+
foreach ($data['table'] as $keyTable => $tableColumns) {
88+
foreach ($tableColumns['column'] as $keyColumn => $columnData) {
89+
if ($columnData['type'] == 'json') {
90+
$tablesWithJsonTypeField[$keyTable] = $keyColumn;
91+
}
92+
}
93+
}
94+
8195
foreach ($this->sharding->getResources() as $resource) {
8296
foreach ($this->dbSchemaReader->readTables($resource) as $tableName) {
8397
$columns = [];
@@ -105,7 +119,6 @@ public function build(Schema $schema)
105119
);
106120

107121
$isJsonType = false;
108-
$tablesWithJsonTypeField = $this->getTablesWithJsonTypeField();
109122
if (count($tablesWithJsonTypeField) > 0 && isset($tablesWithJsonTypeField[$tableName])) {
110123
$isJsonType = true;
111124
}
@@ -223,25 +236,4 @@ private function resolveInternalRelations(array $columns, array $data)
223236

224237
return $referenceColumns;
225238
}
226-
227-
/**
228-
* Get tables name with JSON type fields.
229-
*
230-
* @return array
231-
*/
232-
public function getTablesWithJsonTypeField(): array
233-
{
234-
return $this->tablesWithJsonTypeField;
235-
}
236-
237-
/**
238-
* Set tables name with JSON type fields.
239-
*
240-
* @param array $tablesWithJsonTypeField
241-
* @return array
242-
*/
243-
public function setTablesWithJsonTypeField(array $tablesWithJsonTypeField): array
244-
{
245-
return $this->tablesWithJsonTypeField = $tablesWithJsonTypeField;
246-
}
247239
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,7 @@ 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-
}
7465
$schema = $this->schemaFactory->create();
75-
$this->dbSchemaBuilder->setTablesWithJsonTypeField($tablesWithJsonTypeField);
7666
$schema = $this->dbSchemaBuilder->build($schema);
7767
return $schema;
7868
}

0 commit comments

Comments
 (0)