1
0
Fork 0
mirror of synced 2024-08-04 04:52:03 +12:00

feat: add migration

This commit is contained in:
Christy Jacob 2023-04-14 00:38:48 +04:00
parent d48dec3c87
commit ef65d5a224
2 changed files with 60 additions and 0 deletions

View file

@ -54,6 +54,7 @@ abstract class Migration
'1.2.1' => 'V17',
'1.3.0' => 'V18',
'1.3.1' => 'V18',
'1.4.0' => 'V19',
];
/**

View file

@ -0,0 +1,59 @@
<?php
namespace Appwrite\Migration\Version;
use Appwrite\Migration\Migration;
use Utopia\CLI\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
class V19 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() . ')');
$this->projectDB->setNamespace("_{$this->project->getInternalId()}");
Console::info('Migrating Documents');
$this->forEachDocument([$this, 'fixDocument']);
}
/**
* Fix run on each document
*
* @param Document $document
* @return Document
*/
protected function fixDocument(Document $document): Document
{
switch ($document->getCollection()) {
case 'projects':
/**
* Bump version number.
*/
$document->setAttribute('version', '1.4.0');
/**
* Set default disallowPersonalData to false.
*/
$document->setAttribute('auths', array_merge($document->getAttribute('auths', []), [
'disallowPersonalData' => false
]));
break;
}
return $document;
}
}