Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions lib/Db/MagicMapper/MagicTableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,40 @@
if (($tableExists === true) && ($force === false)) {
// Table exists and not forcing update - check if schema changed.
if ($this->magicMapper->hasRegisterSchemaChanged(register: $register, schema: $schema) === false) {
$this->logger->debug(
message: '[MagicTableHandler] Table exists and schema unchanged, skipping',
// Sanity check: verify all schema columns exist in the table.
// The version hash can be stale if it was stored without a full sync.
$requiredColumns = $this->magicMapper->buildTableColumnsFromSchema(schema: $schema);
$currentColumns = $this->magicMapper->getExistingTableColumns(tableName: $tableName);
$missingColumns = array_diff_key($requiredColumns, array_flip($currentColumns));

Check failure on line 118 in lib/Db/MagicMapper/MagicTableHandler.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (phpstan)

Parameter #1 $array of function array_flip expects array<int|string>, array<array> given.

if (empty($missingColumns) === true) {
$this->logger->debug(
message: '[MagicTableHandler] Table exists and schema unchanged, skipping',
context: [
'file' => __FILE__,
'line' => __LINE__,
'tableName' => $tableName,
'cacheKey' => $cacheKey,
]
);
return true;
}

$this->logger->warning(
message: '[MagicTableHandler] Schema version unchanged but columns missing, forcing sync',
context: [
'file' => __FILE__,
'line' => __LINE__,
'tableName' => $tableName,
'cacheKey' => $cacheKey,
'file' => __FILE__,
'line' => __LINE__,
'tableName' => $tableName,
'missingColumns' => array_keys($missingColumns),
]
);
return true;
}
}//end if

// Schema changed, update table.
// Schema changed or columns missing, update table.
$result = $this->syncTableForRegisterSchema(register: $register, schema: $schema);
return $result['success'] ?? true;
}
}//end if

// Create new table or recreate if forced.
if (($tableExists === true) && ($force === true)) {
Expand Down
Loading