feat(migration): add 0.10.x migration
This commit is contained in:
parent
09aea0fd95
commit
8639070115
|
@ -72,7 +72,7 @@ $cli
|
|||
$sum = \count($projects);
|
||||
$offset = $offset + $limit;
|
||||
$count = $count + $sum;
|
||||
|
||||
|
||||
if ($sum > 0) {
|
||||
Console::log('Fetched '.$count.'/'.$consoleDB->getSum().' projects...');
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ abstract class Migration
|
|||
'0.9.2' => 'V08',
|
||||
'0.9.3' => 'V08',
|
||||
'0.9.4' => 'V08',
|
||||
'0.10.0' => 'V08',
|
||||
'0.10.0' => 'V09',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
48
src/Appwrite/Migration/Version/V09.php
Normal file
48
src/Appwrite/Migration/Version/V09.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Migration\Version;
|
||||
|
||||
use Appwrite\Migration\Migration;
|
||||
use Utopia\CLI\Console;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Document;
|
||||
|
||||
class V09 extends Migration
|
||||
{
|
||||
public function execute(): void
|
||||
{
|
||||
$project = $this->project;
|
||||
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
||||
|
||||
$this->forEachDocument([$this, 'fixDocument']);
|
||||
}
|
||||
|
||||
protected function fixDocument(Document $document)
|
||||
{
|
||||
switch ($document->getAttribute('$collection')) {
|
||||
/**
|
||||
* Add version reference to database.
|
||||
*/
|
||||
case Database::SYSTEM_COLLECTION_PROJECTS:
|
||||
$document->setAttribute('version', '0.10.0');
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($document as &$attr) {
|
||||
if ($attr instanceof Document) {
|
||||
$attr = $this->fixDocument($attr);
|
||||
}
|
||||
|
||||
if (\is_array($attr)) {
|
||||
foreach ($attr as &$child) {
|
||||
if ($child instanceof Document) {
|
||||
$child = $this->fixDocument($child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
}
|
31
tests/unit/Migration/MigrationV09Test.php
Normal file
31
tests/unit/Migration/MigrationV09Test.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use ReflectionClass;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Migration\Version\V09;
|
||||
|
||||
class MigrationV09Test extends MigrationTest
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->pdo = new \PDO('sqlite::memory:');
|
||||
$this->migration = new V09($this->pdo);
|
||||
$reflector = new ReflectionClass('Appwrite\Migration\Version\V09');
|
||||
$this->method = $reflector->getMethod('fixDocument');
|
||||
$this->method->setAccessible(true);
|
||||
}
|
||||
|
||||
public function testMigration()
|
||||
{
|
||||
$document = $this->fixDocument(new Document([
|
||||
'$id' => 'project',
|
||||
'$collection' => Database::SYSTEM_COLLECTION_PROJECTS,
|
||||
'version' => '0.9.0'
|
||||
]));
|
||||
|
||||
$this->assertEquals($document->getAttribute('version', '0.9.0'), '0.10.0');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue