From 4ce65876348203ce16f177f027c17a3c737db3cc Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 16 May 2025 20:30:16 +1200 Subject: [PATCH] Fix key matching --- src/Appwrite/Migration/Migration.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index aa8254b0eb..1e6d53554e 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -261,26 +261,30 @@ abstract class Migration throw new Exception("Collection {$from} not found"); } - $attributes = []; - foreach ($attributeIds as $attributeId) { - $attribute = $collection['attributes'][$attributeId] ?? null; + $attributesToCreate = []; + $attributes = $collection['attributes']; + $attributeKeys = \array_column($collection['attributes'], '$id'); - if ($attribute === null) { + foreach ($attributeIds as $attributeId) { + $attributeKey = \array_search($attributeId, $attributeKeys); + + if ($attributeKey === false) { throw new Exception("Attribute {$attributeId} not found"); } + $attribute = $attributes[$attributeKey]; $attribute['filters'] ??= []; $attribute['default'] ??= null; $attribute['default'] = \in_array('json', $attribute['filters']) ? \json_encode($attribute['default']) : $attribute['default']; - $attributes[] = $attribute; + $attributesToCreate[] = $attribute; } $database->createAttributes( collection: $collectionId, - attributes: $attributes, + attributes: $attributesToCreate, ); }