mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Fix index migrations
This commit is contained in:
parent
ecaaff4502
commit
175a117db1
1 changed files with 13 additions and 14 deletions
|
|
@ -84,27 +84,29 @@ class V20 extends Migration
|
||||||
Query::equal('array', [true]),
|
Query::equal('array', [true]),
|
||||||
]) as $attribute
|
]) as $attribute
|
||||||
) {
|
) {
|
||||||
$foundIndex = false;
|
|
||||||
$collectionId = "database_{$attribute['databaseInternalId']}_collection_{$attribute['collectionInternalId']}";
|
$collectionId = "database_{$attribute['databaseInternalId']}_collection_{$attribute['collectionInternalId']}";
|
||||||
|
|
||||||
foreach (
|
foreach (
|
||||||
$this->documentsIterator('indexes', [
|
$this->documentsIterator('indexes', [
|
||||||
Query::equal('databaseInternalId', [$attribute['databaseInternalId']]),
|
Query::equal('databaseInternalId', [$attribute['databaseInternalId']]),
|
||||||
Query::equal('collectionInternalId', [$attribute['collectionInternalId']]),
|
Query::equal('collectionInternalId', [$attribute['collectionInternalId']]),
|
||||||
]) as $index
|
]) as $index
|
||||||
) {
|
) {
|
||||||
if (in_array($attribute->getAttribute('key'), $index->getAttribute('attributes'))) {
|
if (\in_array($attribute->getAttribute('key'), $index->getAttribute('attributes'))) {
|
||||||
try {
|
try {
|
||||||
$this->projectDB->deleteIndex($collectionId, $index->getId());
|
$this->projectDB->deleteIndex($collectionId, $index->getAttribute('key'));
|
||||||
} catch (Throwable $th) {
|
} catch (Throwable $th) {
|
||||||
Console::warning("Failed to delete index: {$th->getMessage()}");
|
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");
|
$this->projectDB->setNamespace("_$internalProjectId");
|
||||||
|
|
||||||
// Support database array type migration
|
// Support database array type migration
|
||||||
$foundIndex = false;
|
|
||||||
foreach ($collection['attributes'] ?? [] as $attribute) {
|
foreach ($collection['attributes'] ?? [] as $attribute) {
|
||||||
if ($attribute['array'] === true) {
|
if ($attribute['array'] === true) {
|
||||||
foreach ($collection['indexes'] ?? [] as $index) {
|
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']);
|
$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']);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue