new migration
This commit is contained in:
parent
fe472e5b36
commit
16b80e1ef8
1 changed files with 103 additions and 0 deletions
103
src/Appwrite/Migration/Version/V18.php
Normal file
103
src/Appwrite/Migration/Version/V18.php
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Migration\Version;
|
||||||
|
|
||||||
|
use Appwrite\Auth\Auth;
|
||||||
|
use Appwrite\Migration\Migration;
|
||||||
|
use Utopia\CLI\Console;
|
||||||
|
use Utopia\Config\Config;
|
||||||
|
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 'users':
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* Create 'passwordHistory' attribute
|
||||||
|
*/
|
||||||
|
$this->createAttributeFromCollection($this->projectDB, $id, 'passwordHistory');
|
||||||
|
$this->projectDB->deleteCachedCollection($id);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Console::warning("'region' 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)
|
||||||
|
{
|
||||||
|
switch ($document->getCollection()) {
|
||||||
|
case 'projects':
|
||||||
|
/**
|
||||||
|
* Bump version number.
|
||||||
|
*/
|
||||||
|
$document->setAttribute('version', '1.2.0');
|
||||||
|
break;
|
||||||
|
case 'users':
|
||||||
|
/**
|
||||||
|
* Bump version number.
|
||||||
|
*/
|
||||||
|
$document->setAttribute('passwordHistory', []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default passwordHistory
|
||||||
|
*/
|
||||||
|
$document->setAttribute('auths', array_merge($document->getAttribute('auths', []), [
|
||||||
|
'passwordHistory' => 0
|
||||||
|
]));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue