#25: Updated the data migration framework to run all intermediate versions
This commit is contained in:
parent
6d11f1c0f0
commit
22d446d246
@ -4,5 +4,15 @@ namespace App;
|
||||
|
||||
abstract class DataMigration
|
||||
{
|
||||
/**
|
||||
* Gets the version number this data migration applies to.
|
||||
* @return string
|
||||
*/
|
||||
abstract function getVersion();
|
||||
|
||||
/**
|
||||
* Runs this data migration.
|
||||
* @param string $currentVersion Current version being upgraded from.
|
||||
*/
|
||||
abstract function run($currentVersion);
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Configuration;
|
||||
use App\DataMigration;
|
||||
use App\Facade\UserConfig;
|
||||
use App\Helpers\MiscHelper;
|
||||
@ -99,16 +98,39 @@ class AppInstallation
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
Artisan::call('db:seed', ['--force' => true]);
|
||||
|
||||
$className = sprintf('DataMigrationV%s', str_replace(['.', '-'], '_', $appVersionNumber));
|
||||
if (class_exists($className))
|
||||
// Run any data migrations relevant to the new version
|
||||
$dataMigrationsFolder = join(DIRECTORY_SEPARATOR, [dirname(dirname(dirname(__DIR__))), 'database', 'data_migrations']);
|
||||
$di = new \RecursiveDirectoryIterator($dataMigrationsFolder, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$updateClasses = [];
|
||||
|
||||
// First load all data migration classes and examine the version number to decide if we need it or not
|
||||
/** @var \SplFileInfo $fileInfo */
|
||||
foreach ($di as $fileInfo)
|
||||
{
|
||||
if (!$di->isFile() || $di->getExtension() != 'php')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$className = substr($fileInfo->getFilename(), 0, strlen($fileInfo->getFilename()) - 4);
|
||||
|
||||
/** @var DataMigration $upgradeClass */
|
||||
$upgradeClass = new $className;
|
||||
$upgradeClass->run($versionNumber);
|
||||
if (version_compare($versionNumber->value, $upgradeClass->getVersion()) < 0)
|
||||
{
|
||||
$updateClasses[] = $upgradeClass;
|
||||
}
|
||||
}
|
||||
|
||||
// Now run the migrations
|
||||
foreach ($updateClasses as $upgradeClass)
|
||||
{
|
||||
$upgradeClass->run($versionNumber);
|
||||
}
|
||||
|
||||
// Save the new version number
|
||||
$versionNumber->value = $appVersionNumber;
|
||||
$versionNumber->save();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
return [
|
||||
// Version number of Blue Twilight
|
||||
'version' => '2.0.0-alpha.2',
|
||||
'version' => '2.0.0-beta.1',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -5,6 +5,11 @@ use App\DataMigration;
|
||||
|
||||
class DataMigrationV2_0_0_alpha_1 extends DataMigration
|
||||
{
|
||||
public function getVersion()
|
||||
{
|
||||
return '2.0.0-alpha.1';
|
||||
}
|
||||
|
||||
public function run($currentVersion)
|
||||
{
|
||||
$this->storeAlbumUrlPaths();
|
||||
|
Loading…
Reference in New Issue
Block a user