Implement Keystone environment deployments
This commit is contained in:
44
app/Actions/Environments/CreateMigrationOperation.php
Normal file
44
app/Actions/Environments/CreateMigrationOperation.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Environments;
|
||||
|
||||
use App\Enums\OperationKind;
|
||||
use App\Enums\OperationStatus;
|
||||
use App\Enums\ServiceType;
|
||||
use App\Models\Environment;
|
||||
use App\Models\Operation;
|
||||
use App\Models\Service;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class CreateMigrationOperation
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BuildMigrationScript $buildMigrationScript,
|
||||
) {}
|
||||
|
||||
public function execute(Environment $environment, ?Service $service = null): Operation
|
||||
{
|
||||
$service ??= $environment->services()
|
||||
->where('type', ServiceType::LARAVEL)
|
||||
->get()
|
||||
->first(fn (Service $service): bool => in_array('web', $service->process_roles ?? [], true));
|
||||
|
||||
if (! $service || $service->type !== ServiceType::LARAVEL) {
|
||||
throw new InvalidArgumentException('Laravel migrations must run against a Laravel runtime service.');
|
||||
}
|
||||
|
||||
$operation = $service->operations()->create([
|
||||
'kind' => OperationKind::CONFIG_CHANGE,
|
||||
'status' => OperationStatus::PENDING,
|
||||
]);
|
||||
|
||||
$operation->steps()->create([
|
||||
'name' => 'Run Laravel migrations',
|
||||
'order' => 1,
|
||||
'status' => OperationStatus::PENDING,
|
||||
'script' => $this->buildMigrationScript->execute($service, respectAutomaticMode: false),
|
||||
]);
|
||||
|
||||
return $operation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user