diff --git a/app/tasks/migrate.php b/app/tasks/migrate.php index dad0847e97..60aad941d1 100644 --- a/app/tasks/migrate.php +++ b/app/tasks/migrate.php @@ -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) { diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index ed18bf85ee..0d6995b064 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -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. * diff --git a/src/Appwrite/Migration/Version/V04.php b/src/Appwrite/Migration/Version/V04.php deleted file mode 100644 index 3b13d8920b..0000000000 --- a/src/Appwrite/Migration/Version/V04.php +++ /dev/null @@ -1,14 +0,0 @@ - $class) { + $this->assertTrue(class_exists('Appwrite\\Migration\\Version\\'.$class)); + } + // Test if current version exists + $this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions); + } }