Implement migration for mimeType
This commit is contained in:
parent
ea58cb4aff
commit
0a177713f0
2 changed files with 80 additions and 0 deletions
|
@ -48,6 +48,7 @@ abstract class Migration
|
||||||
'1.1.0' => 'V16',
|
'1.1.0' => 'V16',
|
||||||
'1.1.1' => 'V16',
|
'1.1.1' => 'V16',
|
||||||
'1.1.2' => 'V16',
|
'1.1.2' => 'V16',
|
||||||
|
'1.2.0' => 'V17',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
79
src/Appwrite/Migration/Version/V17.php
Normal file
79
src/Appwrite/Migration/Version/V17.php
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
<?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) {
|
||||||
|
case 'files':
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* Update 'mimeType' attribute size (127->255)
|
||||||
|
*/
|
||||||
|
$this->projectDB->updateAttribute($id, 'mimeType', Database::VAR_STRING, 255, true, false);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Console::warning("'mimeType' from {$id}: {$th->getMessage()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue