for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\DbSnapshots\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Spatie\DbSnapshots\Commands\Concerns\AsksForSnapshotName;
use Spatie\DbSnapshots\SnapshotRepository;
class Load extends Command
{
use AsksForSnapshotName;
use ConfirmableTrait;
protected $signature = 'snapshot:load {name?} {--connection=} {--force} --disk {--latest}';
protected $description = 'Load up a snapshot.';
public function handle()
$snapShots = app(SnapshotRepository::class)->getAll();
if ($snapShots->isEmpty()) {
$this->warn('No snapshots found. Run `snapshot:create` first to create snapshots.');
return;
}
if (! $this->confirmToProceed()) {
$useLatestSnapshot = $this->option('latest') ?: false;
$name = $useLatestSnapshot
? $snapShots->last()->name
: $this->argument('name') ?: $this->askForSnapshotName();
$snapshot = app(SnapshotRepository::class)->findByName($name);
if (! $snapshot) {
$this->warn("Snapshot `{$name}` does not exist!");
$snapshot->load($this->option('connection'));
$this->info("Snapshot `{$name}` loaded!");