2022-12-12 12:39:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Migration\Version;
|
|
|
|
|
|
|
|
|
|
use Appwrite\Migration\Migration;
|
|
|
|
|
use Utopia\CLI\Console;
|
|
|
|
|
use Utopia\Database\Database;
|
|
|
|
|
use Utopia\Database\Document;
|
|
|
|
|
|
|
|
|
|
class V17 extends Migration
|
|
|
|
|
{
|
|
|
|
|
public function execute(): void
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Disable SubQueries for Performance.
|
|
|
|
|
*/
|
|
|
|
|
foreach (['subQueryIndexes', 'subQueryPlatforms', 'subQueryDomains', 'subQueryKeys', 'subQueryWebhooks', 'subQuerySessions', 'subQueryTokens', 'subQueryMemberships', 'subqueryVariables'] as $name) {
|
|
|
|
|
Database::addFilter(
|
|
|
|
|
$name,
|
|
|
|
|
fn () => null,
|
|
|
|
|
fn () => []
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console::log('Migrating Project: ' . $this->project->getAttribute('name') . ' (' . $this->project->getId() . ')');
|
|
|
|
|
|
|
|
|
|
Console::info('Migrating Collections');
|
|
|
|
|
$this->migrateCollections();
|
|
|
|
|
|
|
|
|
|
// Console::info('Migrating Documents');
|
|
|
|
|
// $this->forEachDocument([$this, 'fixDocument']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Migrate all Collections.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function migrateCollections(): void
|
|
|
|
|
{
|
|
|
|
|
foreach ($this->collections as $collection) {
|
|
|
|
|
$id = $collection['$id'];
|
|
|
|
|
|
|
|
|
|
Console::log("Migrating Collection \"{$id}\"");
|
|
|
|
|
|
|
|
|
|
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
|
|
|
|
|
|
|
|
|
|
switch ($id) {
|
2022-12-07 11:01:58 +00:00
|
|
|
case 'files':
|
|
|
|
|
try {
|
|
|
|
|
/**
|
|
|
|
|
* Update 'mimeType' attribute size (127->255)
|
|
|
|
|
*/
|
|
|
|
|
$this->projectDB->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false);
|
2022-12-16 09:39:53 +00:00
|
|
|
$this->projectDB->deleteCachedCollection($id);
|
2022-12-07 11:01:58 +00:00
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
Console::warning("'mimeType' from {$id}: {$th->getMessage()}");
|
|
|
|
|
}
|
|
|
|
|
break;
|
2022-12-12 12:39:43 +00:00
|
|
|
case 'builds':
|
|
|
|
|
try {
|
|
|
|
|
/**
|
2022-12-18 07:20:50 +00:00
|
|
|
* Create 'size' attribute
|
2022-12-12 12:39:43 +00:00
|
|
|
*/
|
2022-12-18 07:20:50 +00:00
|
|
|
$this->createAttributeFromCollection($this->projectDB, $id, 'size');
|
2022-12-12 12:39:43 +00:00
|
|
|
} catch (\Throwable $th) {
|
2022-12-18 07:20:50 +00:00
|
|
|
Console::warning("'size' from {$id}: {$th->getMessage()}");
|
2022-12-12 12:39:43 +00:00
|
|
|
}
|
2022-12-12 12:52:22 +00:00
|
|
|
break;
|
2022-12-12 12:39:43 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usleep(50000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fix run on each document
|
|
|
|
|
*
|
|
|
|
|
* @param \Utopia\Database\Document $document
|
|
|
|
|
* @return \Utopia\Database\Document
|
|
|
|
|
*/
|
|
|
|
|
protected function fixDocument(Document $document)
|
|
|
|
|
{
|
|
|
|
|
return $document;
|
|
|
|
|
}
|
2022-12-12 12:45:21 +00:00
|
|
|
}
|