Add parent attribute and index to files collections with V25 migration

This commit is contained in:
Torsten Dittmann committed 2026-07-06 20:05:00 +04:00
1 parent db11c8fcc6
commit eb72169b89
2 files changed
+56

No files matched your search

+18
View File
@@ -2530,6 +2530,17 @@ return [
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('parent'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 2048,
'signed' => true,
'required' => false,
'default' => '',
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('signature'),
'type' => Database::VAR_STRING,
@@ -2718,6 +2729,13 @@ return [
'lengths' => [256],
'orders' => [Database::ORDER_ASC],
],
[
'$id' => ID::custom('_key_parent'),
'type' => Database::INDEX_KEY,
'attributes' => ['parent'],
'lengths' => [256],
'orders' => [Database::ORDER_ASC],
],
[
'$id' => ID::custom('_key_signature'),
'type' => Database::INDEX_KEY,
+38
View File
@@ -7,6 +7,8 @@ use Exception;
use Throwable;
use Utopia\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\Duplicate;
class V25 extends Migration
{
@@ -17,6 +19,9 @@ class V25 extends Migration
{
Console::info('Migrating collections');
$this->migrateCollections();
Console::info('Migrating buckets');
$this->migrateBuckets();
}
/**
@@ -66,4 +71,37 @@ class V25 extends Migration
}
}
}
/**
* Add the virtual folder `parent` attribute and index to every
* per-bucket files collection.
*
* @return void
* @throws Throwable
*/
private function migrateBuckets(): void
{
$this->dbForProject->foreach('buckets', function (Document $bucket) {
$bucketTable = "bucket_{$bucket->getSequence()}";
Console::log("Migrating Bucket {$bucket->getId()} ({$bucket->getAttribute('name')})");
try {
$this->createAttributeFromCollection($this->dbForProject, $bucketTable, 'parent', 'files');
} catch (Duplicate) {
Console::warning("'parent' from {$bucketTable}: Column already exists");
} catch (Throwable $th) {
Console::warning("'parent' from {$bucketTable}: {$th->getMessage()}");
}
try {
$this->createIndexFromCollection($this->dbForProject, $bucketTable, '_key_parent', 'files');
} catch (Duplicate) {
Console::warning("'_key_parent' from {$bucketTable}: Index already exists");
} catch (Throwable $th) {
Console::warning("'_key_parent' from {$bucketTable}: {$th->getMessage()}");
}
$this->dbForProject->purgeCachedCollection($bucketTable);
});
}
}