1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

Merge pull request #7769 from appwrite/fix-index-migrations

Fix index migrations
This commit is contained in:
Torsten Dittmann 2024-03-09 16:55:04 +01:00 committed by GitHub
commit 16cd8704d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -84,27 +84,29 @@ class V20 extends Migration
Query::equal('array', [true]),
]) as $attribute
) {
$foundIndex = false;
$collectionId = "database_{$attribute['databaseInternalId']}_collection_{$attribute['collectionInternalId']}";
foreach (
$this->documentsIterator('indexes', [
Query::equal('databaseInternalId', [$attribute['databaseInternalId']]),
Query::equal('collectionInternalId', [$attribute['collectionInternalId']]),
]) as $index
) {
if (in_array($attribute->getAttribute('key'), $index->getAttribute('attributes'))) {
if (\in_array($attribute->getAttribute('key'), $index->getAttribute('attributes'))) {
try {
$this->projectDB->deleteIndex($collectionId, $index->getId());
$this->projectDB->deleteIndex($collectionId, $index->getAttribute('key'));
} catch (Throwable $th) {
Console::warning("Failed to delete index: {$th->getMessage()}");
} finally {
$foundIndex = true;
}
try {
$this->projectDB->deleteDocument('indexes', $index->getId());
} catch (Throwable $th) {
Console::warning("Failed to remove index: {$th->getMessage()}");
}
}
}
if ($foundIndex === true) {
$this->projectDB->updateAttribute($collectionId, $attribute['key'], $attribute['type']);
}
$this->projectDB->updateAttribute($collectionId, $attribute['key'], $attribute['type']);
}
}
@ -117,18 +119,15 @@ class V20 extends Migration
$this->projectDB->setNamespace("_$internalProjectId");
// Support database array type migration
$foundIndex = false;
foreach ($collection['attributes'] ?? [] as $attribute) {
if ($attribute['array'] === true) {
foreach ($collection['indexes'] ?? [] as $index) {
if (in_array($attribute['$id'], $index['attributes'])) {
if (\in_array($attribute['$id'], $index['attributes'])) {
$this->projectDB->deleteIndex($id, $index['$id']);
$foundIndex = true;
}
}
if ($foundIndex === true) {
$this->projectDB->updateAttribute($id, $attribute['$id'], $attribute['type']);
}
$this->projectDB->updateAttribute($id, $attribute['$id'], $attribute['type']);
}
}