(fix): register related collection ID mappings and update migration lib

- getDatabasesDB now registers mappings for related collections from
  relationship attributes, not just the primary collection. This fixes
  testOneToOneRelationship where nested documents showed internal names.
- Update utopia-php/migration to handle Index objects in createCollection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jake Barnby
2026-04-02 03:01:58 +13:00
co-authored by Claude Opus 4.6
parent 5740cecbe5
commit 95552031ef
2 changed files with 33 additions and 5 deletions
+29 -1
View File
@@ -776,12 +776,40 @@ Http::setResource('getDatabasesDB', function (Group $pools, Cache $cache, Docume
// Register collection ID mapping if collection document is provided
if ($collection !== null && !$collection->isEmpty()) {
$dbSeq = $originalDatabase->getSequence();
$dbPrefix = 'database_' . $dbSeq;
$seq = $collection->getSequence();
if ($seq !== null) {
$dbPrefix = 'database_' . $originalDatabase->getSequence();
$metadata->setCollectionId('collection_' . $seq, $collection->getId());
$metadata->setCollectionId($dbPrefix . '_collection_' . $seq, $collection->getId());
}
// Also register related collections from relationship attributes
$attributes = $collection->getAttribute('attributes', []);
foreach ($attributes as $attr) {
if ($attr->getAttribute('type') !== \Utopia\Query\Schema\ColumnType::Relationship->value) {
continue;
}
$options = $attr->getAttribute('options', []);
$relatedId = \is_array($options) ? ($options['relatedCollection'] ?? null) : null;
$relatedId ??= $attr->getAttribute('relatedCollection');
if ($relatedId === null) {
continue;
}
// Look up the related collection from dbForProject
$relatedCol = $authorization->skip(
fn () => $dbForProject->silent(
fn () => $dbForProject->getDocument($dbPrefix, $relatedId)
)
);
if (!$relatedCol->isEmpty()) {
$relSeq = $relatedCol->getSequence();
if ($relSeq !== null) {
$metadata->setCollectionId('collection_' . $relSeq, $relatedCol->getId());
$metadata->setCollectionId($dbPrefix . '_collection_' . $relSeq, $relatedCol->getId());
}
}
}
}
$database
Generated
+4 -4
View File
@@ -4708,12 +4708,12 @@
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "7c0e2d4f065c72f8b8424bbc06cb4aecbf28915a"
"reference": "1bc59979ee7a1af5f98333f277cad27785ef30c1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/7c0e2d4f065c72f8b8424bbc06cb4aecbf28915a",
"reference": "7c0e2d4f065c72f8b8424bbc06cb4aecbf28915a",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/1bc59979ee7a1af5f98333f277cad27785ef30c1",
"reference": "1bc59979ee7a1af5f98333f277cad27785ef30c1",
"shasum": ""
},
"require": {
@@ -4773,7 +4773,7 @@
"source": "https://github.com/utopia-php/migration/tree/feat-query-lib",
"issues": "https://github.com/utopia-php/migration/issues"
},
"time": "2026-03-31T11:14:26+00:00"
"time": "2026-04-01T14:01:14+00:00"
},
{
"name": "utopia-php/mongo",