From 480c1515b4d5db219ceb6f9699a3cfb5f658fda6 Mon Sep 17 00:00:00 2001 From: Alec Smecher Date: Fri, 18 Feb 2022 15:16:01 -0800 Subject: [PATCH] pkp/pkp-lib#7678 Relax unique index for merged users case --- classes/migration/install/ReviewsMigration.inc.php | 6 +++++- .../migration/upgrade/v3_4_0/UpgradeMigration.inc.php | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/classes/migration/install/ReviewsMigration.inc.php b/classes/migration/install/ReviewsMigration.inc.php index ded097a81bf..114e10b7307 100644 --- a/classes/migration/install/ReviewsMigration.inc.php +++ b/classes/migration/install/ReviewsMigration.inc.php @@ -78,7 +78,11 @@ public function up(): void $table->smallInteger('unconsidered')->nullable(); - $table->unique(['review_round_id', 'reviewer_id'], 'review_assignment_reviewer_round_unique'); + // Normally reviewer can't be assigned twice on the same review round. + // HOWEVER, if two reviewer user accounts are subsequently merged, both will keep + // separate review assignments but the reviewer_id will become the same! + // (https://github.com/pkp/pkp-lib/issues/7678) + $table->index(['review_round_id', 'reviewer_id'], 'review_assignment_reviewer_round'); $table->index(['submission_id'], 'review_assignments_submission_id'); $table->index(['reviewer_id'], 'review_assignments_reviewer_id'); $table->index(['review_form_id'], 'review_assignments_form_id'); diff --git a/classes/migration/upgrade/v3_4_0/UpgradeMigration.inc.php b/classes/migration/upgrade/v3_4_0/UpgradeMigration.inc.php index 5c44f6f8aed..0f3f7c6c90d 100755 --- a/classes/migration/upgrade/v3_4_0/UpgradeMigration.inc.php +++ b/classes/migration/upgrade/v3_4_0/UpgradeMigration.inc.php @@ -58,8 +58,12 @@ public function up(): void $table->foreign('reviewer_id')->references('user_id')->on('users'); $table->foreign('review_round_id')->references('review_round_id')->on('review_rounds'); $table->foreign('review_form_id')->references('review_form_id')->on('review_forms'); - // No reviewer can be assigned twice on the same review round. - $table->unique(['review_round_id', 'reviewer_id'], 'review_assignment_reviewer_round_unique'); + + // Normally reviewer can't be assigned twice on the same review round. + // HOWEVER, if two reviewer user accounts are subsequently merged, both will keep + // separate review assignments but the reviewer_id will become the same! + // (https://github.com/pkp/pkp-lib/issues/7678) + $table->index(['review_round_id', 'reviewer_id'], 'review_assignment_reviewer_round'); }); // pkp/pkp-lib#6685: Drop old tombstones table in OJS and OPS @@ -90,7 +94,7 @@ public function down(): void $table->dropForeign(['review_form_id']); }); Schema::table('review_assignments', function (Blueprint $table) { - $table->dropUnique('review_assignment_reviewer_round_unique'); + $table->dropIndex('review_assignment_reviewer_round'); }); Schema::table('users', function (Blueprint $table) { $table->dateTime('date_last_login')->nullable(false)->default(null)->change();