2023_05_11_012354_update_failed_jobs.php 885 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. Schema::table('failed_jobs', static function (Blueprint $table) {
  13. $table->string('uuid')->after('id')->nullable()->unique();
  14. });
  15. DB::table('failed_jobs')->whereNull('uuid')->cursor()->each(function ($job) {
  16. DB::table('failed_jobs')
  17. ->where('id', $job->id)
  18. ->update(['uuid' => (string) Illuminate\Support\Str::uuid()]);
  19. });
  20. }
  21. /**
  22. * Reverse the migrations.
  23. */
  24. public function down(): void
  25. {
  26. Schema::table('failed_jobs', function (Blueprint $table) {
  27. $table->dropColumn('uuid');
  28. });
  29. }
  30. };