BLUE-10: Added a clause that runs the DB migration whenever the version number differs
This commit is contained in:
parent
975c4938b4
commit
acf8215105
@ -3,10 +3,13 @@
|
|||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use App\Configuration;
|
use App\Configuration;
|
||||||
|
use App\Facade\UserConfig;
|
||||||
use App\Helpers\MiscHelper;
|
use App\Helpers\MiscHelper;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class AppInstallation
|
class AppInstallation
|
||||||
{
|
{
|
||||||
@ -61,6 +64,9 @@ class AppInstallation
|
|||||||
|
|
||||||
if ($isAppInstalled)
|
if ($isAppInstalled)
|
||||||
{
|
{
|
||||||
|
// See if an update is necessary
|
||||||
|
$this->updateDatabaseIfRequired();
|
||||||
|
|
||||||
// App is configured, continue on
|
// App is configured, continue on
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@ -78,4 +84,21 @@ class AppInstallation
|
|||||||
app('config')->set(['app' => ['key' => $key]]);
|
app('config')->set(['app' => ['key' => $key]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateDatabaseIfRequired()
|
||||||
|
{
|
||||||
|
$versionNumber = UserConfig::getOrCreateModel('app_version');
|
||||||
|
$appVersionNumber = config('app.version');
|
||||||
|
|
||||||
|
if (is_null($appVersionNumber) || $versionNumber->value != $appVersionNumber)
|
||||||
|
{
|
||||||
|
Log::info('Upgrading database', ['new_version' => $appVersionNumber]);
|
||||||
|
|
||||||
|
Artisan::call('cache:clear');
|
||||||
|
Artisan::call('migrate', ['--force' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$versionNumber->value = $appVersionNumber;
|
||||||
|
$versionNumber->save();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user