cattr-app/server-application

View on GitHub
database/migrations/2021_02_02_090745_drop_screenshots_model.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

use App\Contracts\ScreenshotService;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        DB::table('screenshots')
            ->lazyById()
            ->each(static function ($screenshot) {
                rescue(static fn() => app(ScreenshotService::class)->saveScreenshot(
                    Storage::path($screenshot->path),
                    $screenshot->time_interval_id
                ));
            });

        Storage::deleteDirectory('uploads/screenshots');

        Schema::drop('screenshots');
    }

    public function down(): void
    {
        //
    }
};