Fixes for installer/modules race condition (#883)
This commit is contained in:
@@ -47,6 +47,7 @@ class DatabaseService extends Service
|
||||
} catch (\PDOException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,16 @@
|
||||
namespace App\Services\Installer;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use Exception;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class MigrationService extends Service
|
||||
{
|
||||
protected function getMigrator()
|
||||
protected function getMigrator(): Migrator
|
||||
{
|
||||
$m = app('migrator');
|
||||
$m->setConnection(config('database.default'));
|
||||
@@ -36,8 +39,6 @@ class MigrationService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
// Log::info('Update - migration paths', $paths);
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
@@ -49,10 +50,25 @@ class MigrationService extends Service
|
||||
$migrator = $this->getMigrator();
|
||||
$migration_dirs = $this->getMigrationPaths();
|
||||
|
||||
$files = $migrator->getMigrationFiles(array_values($migration_dirs));
|
||||
$availMigrations = array_diff(array_keys($files), $migrator->getRepository()->getRan());
|
||||
$availMigrations = [];
|
||||
$runFiles = [];
|
||||
|
||||
// Log::info('Migrations available:', $availMigrations);
|
||||
try {
|
||||
$runFiles = $migrator->getRepository()->getRan();
|
||||
} catch (Exception $e) {
|
||||
} // Skip database run initialized
|
||||
|
||||
$files = $migrator->getMigrationFiles(array_values($migration_dirs));
|
||||
|
||||
foreach ($files as $filename => $filepath) {
|
||||
if (in_array($filename, $runFiles, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$availMigrations[] = $filepath;
|
||||
}
|
||||
|
||||
Log::info('Migrations available:', $availMigrations);
|
||||
|
||||
return $availMigrations;
|
||||
}
|
||||
@@ -63,11 +79,23 @@ class MigrationService extends Service
|
||||
*/
|
||||
public function runAllMigrations()
|
||||
{
|
||||
// A little ugly, run the main migration first, this makes sure the migration table is there
|
||||
$output = '';
|
||||
|
||||
Artisan::call('migrate');
|
||||
$output .= trim(Artisan::output());
|
||||
|
||||
return $output;
|
||||
// Then get any remaining migrations that are left over
|
||||
// Due to caching or whatever reason, the migrations are not all loaded when Artisan first
|
||||
// runs. This is likely a side effect of the database being used as the module activator,
|
||||
// and the list of migrations being pulled before the initial modules are populated
|
||||
$migrator = $this->getMigrator();
|
||||
$availMigrations = $this->migrationsAvailable();
|
||||
|
||||
Log::info('Running '.count($availMigrations).' available migrations');
|
||||
$ret = $migrator->run($availMigrations);
|
||||
Log::info('Ran '.count($ret).' migrations');
|
||||
|
||||
return $output."\n".implode("\n", $ret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,10 +56,10 @@ class SeederService extends Service
|
||||
*/
|
||||
public function syncAllSeeds(): void
|
||||
{
|
||||
$this->syncAllYamlFileSeeds();
|
||||
$this->syncAllSettings();
|
||||
$this->syncAllPermissions();
|
||||
$this->syncAllModules();
|
||||
$this->syncAllYamlFileSeeds();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,8 +125,12 @@ class ModuleService extends Service
|
||||
'name' => $module_name,
|
||||
'enabled' => 1,
|
||||
]);
|
||||
|
||||
Artisan::call('module:migrate '.$module_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -240,6 +244,11 @@ class ModuleService extends Service
|
||||
$module->update([
|
||||
'enabled' => $status,
|
||||
]);
|
||||
|
||||
if ($status === true) {
|
||||
Artisan::call('module:migrate '.$module->name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user