mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Add folder attribute and index to files collections with V25 migration
This commit is contained in:
1 parent
99969aa366
commit
9f62f074ed
2 files changed
+56
No files matched your search
@@ -2662,6 +2662,17 @@ return [
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('folder'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 2048,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => '',
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('signature'),
|
||||
'type' => Database::VAR_STRING,
|
||||
@@ -2850,6 +2861,13 @@ return [
|
||||
'lengths' => [256],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_folder'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['folder'],
|
||||
'lengths' => [256],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_signature'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
|
||||
@@ -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 `folder` 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, 'folder', 'files');
|
||||
} catch (Duplicate) {
|
||||
Console::warning("'folder' from {$bucketTable}: Column already exists");
|
||||
} catch (Throwable $th) {
|
||||
Console::warning("'folder' from {$bucketTable}: {$th->getMessage()}");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->createIndexFromCollection($this->dbForProject, $bucketTable, '_key_folder', 'files');
|
||||
} catch (Duplicate) {
|
||||
Console::warning("'_key_folder' from {$bucketTable}: Index already exists");
|
||||
} catch (Throwable $th) {
|
||||
Console::warning("'_key_folder' from {$bucketTable}: {$th->getMessage()}");
|
||||
}
|
||||
|
||||
$this->dbForProject->purgeCachedCollection($bucketTable);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user