From f3e80be839942aace54ca0c1b971844585e4d6aa Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Fri, 14 Oct 2022 17:13:47 -0500 Subject: [PATCH 1/6] Update `failed_jobs` table to add missing `uuid` column. This also updates the `payload` and `exception` columns to be inline with default the laravel migration. --- ...022_10_14_000027_Db_Failed_Jobs_Update.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php diff --git a/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php b/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php new file mode 100644 index 0000000000..f36bf8f7d4 --- /dev/null +++ b/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php @@ -0,0 +1,27 @@ +getTableName(), function (Blueprint $table) { + $table->string('uuid')->unique()->after('id'); + $table->longText('payload')->change(); + $table->longText('exception')->nullable(false)->change(); + }); + } + + public function down() + { + Schema::table($this->getTableName(), function (Blueprint $table) { + $table->dropColumn('uuid'); + }); + } + + protected function getTableName() + { + return Config::get('queue.failed.table', 'failed_jobs'); + } +}; From ce314cc7d4ddc5525381a7c14173e07be586f578 Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Fri, 14 Oct 2022 17:22:30 -0500 Subject: [PATCH 2/6] Make `uuid` nullable so we don't throw an error when migrating a database with existing failed jobs. --- .../migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php b/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php index f36bf8f7d4..8b8138b943 100644 --- a/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php +++ b/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php @@ -7,9 +7,9 @@ public function up() { Schema::table($this->getTableName(), function (Blueprint $table) { - $table->string('uuid')->unique()->after('id'); + $table->string('uuid')->nullable()->unique()->after('id'); $table->longText('payload')->change(); - $table->longText('exception')->nullable(false)->change(); + $table->longText('exception')->change(); }); } From a198b29aa4431ab4a420d9cce60da0d676af507d Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Mon, 17 Oct 2022 10:17:47 -0500 Subject: [PATCH 3/6] Generate UUIDs for existing failed jobs --- .../2022_10_14_000027_Db_Failed_Jobs_Update.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php b/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php index 8b8138b943..5e76d9e047 100644 --- a/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php +++ b/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php @@ -1,6 +1,7 @@ longText('payload')->change(); $table->longText('exception')->change(); }); + + // Generate UUIDs for existing failed jobs + DB::table($this->getTableName())->whereNull('uuid')->cursor()->each(function ($job) { + DB::table($this->getTableName()) + ->where('id', $job->id) + ->update(['uuid' => (string) Str::uuid()]); + }); } public function down() From 2f3fdc64cee2504508b22f20c9fe94c0103c3eac Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Mon, 17 Oct 2022 10:30:26 -0500 Subject: [PATCH 4/6] Change payload column to longtext to be consistent with Laravel's default migration stub. --- ...028_Db_Jobs_Update_Payload_To_Longtext.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php diff --git a/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php b/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php new file mode 100644 index 0000000000..e9a2ffeeda --- /dev/null +++ b/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php @@ -0,0 +1,23 @@ +getTableName(), function (Blueprint $table) { + $table->longText('payload')->change(); + }); + } + + public function down() + { + + } + + protected function getTableName() + { + return Config::get('queue.connections.database.table', 'jobs'); + } +}; From 232995b5ae684620756304be76ce78a264bfe321 Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Mon, 17 Oct 2022 10:35:11 -0500 Subject: [PATCH 5/6] Fix PHP CS error --- .../2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php b/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php index e9a2ffeeda..86b3d81440 100644 --- a/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php +++ b/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php @@ -13,7 +13,6 @@ public function up() public function down() { - } protected function getTableName() From bdb3a7329d5fd9e7a54b70f1a64a83613ec323df Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Mon, 17 Oct 2022 17:36:36 -0500 Subject: [PATCH 6/6] merge both migrations into one file. --- ...0_14_000027_Db_Jobs_FailedJobs_Update.php} | 15 ++++++++++--- ...028_Db_Jobs_Update_Payload_To_Longtext.php | 22 ------------------- 2 files changed, 12 insertions(+), 25 deletions(-) rename modules/system/database/migrations/{2022_10_14_000027_Db_Failed_Jobs_Update.php => 2022_10_14_000027_Db_Jobs_FailedJobs_Update.php} (61%) delete mode 100644 modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php diff --git a/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php b/modules/system/database/migrations/2022_10_14_000027_Db_Jobs_FailedJobs_Update.php similarity index 61% rename from modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php rename to modules/system/database/migrations/2022_10_14_000027_Db_Jobs_FailedJobs_Update.php index 5e76d9e047..aab3662dfa 100644 --- a/modules/system/database/migrations/2022_10_14_000027_Db_Failed_Jobs_Update.php +++ b/modules/system/database/migrations/2022_10_14_000027_Db_Jobs_FailedJobs_Update.php @@ -8,14 +8,18 @@ public function up() { Schema::table($this->getTableName(), function (Blueprint $table) { + $table->longText('payload')->change(); + }); + + Schema::table($this->getFailedTableName(), function (Blueprint $table) { $table->string('uuid')->nullable()->unique()->after('id'); $table->longText('payload')->change(); $table->longText('exception')->change(); }); // Generate UUIDs for existing failed jobs - DB::table($this->getTableName())->whereNull('uuid')->cursor()->each(function ($job) { - DB::table($this->getTableName()) + DB::table($this->getFailedTableName())->whereNull('uuid')->cursor()->each(function ($job) { + DB::table($this->getFailedTableName()) ->where('id', $job->id) ->update(['uuid' => (string) Str::uuid()]); }); @@ -23,12 +27,17 @@ public function up() public function down() { - Schema::table($this->getTableName(), function (Blueprint $table) { + Schema::table($this->getFailedTableName(), function (Blueprint $table) { $table->dropColumn('uuid'); }); } protected function getTableName() + { + return Config::get('queue.connections.database.table', 'jobs'); + } + + protected function getFailedTableName() { return Config::get('queue.failed.table', 'failed_jobs'); } diff --git a/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php b/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php deleted file mode 100644 index 86b3d81440..0000000000 --- a/modules/system/database/migrations/2022_10_17_000028_Db_Jobs_Update_Payload_To_Longtext.php +++ /dev/null @@ -1,22 +0,0 @@ -getTableName(), function (Blueprint $table) { - $table->longText('payload')->change(); - }); - } - - public function down() - { - } - - protected function getTableName() - { - return Config::get('queue.connections.database.table', 'jobs'); - } -};