Merge pull request #1342 from TorstenDittmann/feat-improved-migration
feat(migration): add version chooser
This commit is contained in:
commit
737ba69da0
|
@ -8,12 +8,20 @@ use Appwrite\Database\Database;
|
|||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Migration\Version;
|
||||
use Appwrite\Migration\Migration;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
$cli
|
||||
->task('migrate')
|
||||
->action(function () use ($register) {
|
||||
Console::success('Starting Data Migration');
|
||||
->param('version', APP_VERSION_STABLE, new Text(8), 'Version to migrate to.', true)
|
||||
->action(function ($version) use ($register) {
|
||||
if (!array_key_exists($version, Migration::$versions)) {
|
||||
Console::error("Version {$version} not found.");
|
||||
Console::exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
Console::success('Starting Data Migration to version '.$version);
|
||||
$db = $register->get('db', true);
|
||||
$cache = $register->get('cache', true);
|
||||
|
||||
|
@ -38,7 +46,8 @@ $cli
|
|||
$projects = [$console];
|
||||
$count = 0;
|
||||
|
||||
$migration = new Version\V08($register->get('db')); //TODO: remove hardcoded version and move to dynamic migration
|
||||
$class = 'Appwrite\\Migration\\Version\\'.Migration::$versions[$version];
|
||||
$migration = new $class($register->get('db'));
|
||||
|
||||
while ($sum > 0) {
|
||||
foreach ($projects as $project) {
|
||||
|
|
|
@ -31,6 +31,16 @@ abstract class Migration
|
|||
*/
|
||||
protected $projectDB;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static array $versions = [
|
||||
'0.6.0' => 'V05',
|
||||
'0.7.0' => 'V06',
|
||||
'0.8.0' => 'V07',
|
||||
'0.9.0' => 'V08',
|
||||
];
|
||||
|
||||
/**
|
||||
* Migration constructor.
|
||||
*
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Migration\Version;
|
||||
|
||||
use Utopia\CLI\Console;
|
||||
use Appwrite\Migration\Migration;
|
||||
|
||||
class V04 extends Migration
|
||||
{
|
||||
public function execute(): void
|
||||
{
|
||||
Console::log('I got nothing to do.');
|
||||
}
|
||||
}
|
|
@ -36,4 +36,17 @@ abstract class MigrationTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check versions array integrity.
|
||||
*/
|
||||
public function testMigrationVersions()
|
||||
{
|
||||
require_once __DIR__.'/../../../app/init.php';
|
||||
|
||||
foreach (Migration::$versions as $version => $class) {
|
||||
$this->assertTrue(class_exists('Appwrite\\Migration\\Version\\'.$class));
|
||||
}
|
||||
// Test if current version exists
|
||||
$this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue