fix(results-schema): include Language in unique constraint for CvMatchResults
The unique constraint on cvMatcher.Results was defined as (CvDocumentId, JobDocumentId) but the code checks for (CvDocumentId, JobDocumentId, Language). This mismatch caused duplicate key violations when matching the same CV+Job in different languages. Update the constraint to (CvDocumentId, JobDocumentId, Language) to allow different languages for the same CV+Job pair while preventing true duplicates. Resolves: Duplicate key constraint violations on concurrent/repeated match requests
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CvMatcher.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class UpdateResultsUniqueConstraintToIncludeLanguage : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// The Language column was added in migration 20260524140335, but the unique constraint
|
||||
// was never updated from (CvDocumentId, JobDocumentId) to include Language.
|
||||
// This caused duplicate key violations when matching the same CV+Job in different languages.
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Results_CvDocumentId_JobDocumentId",
|
||||
schema: MigrationConstants.SchemaName,
|
||||
table: "Results");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Results_CvDocumentId_JobDocumentId_Language",
|
||||
schema: MigrationConstants.SchemaName,
|
||||
table: "Results",
|
||||
columns: new[] { "CvDocumentId", "JobDocumentId", "Language" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Results_CvDocumentId_JobDocumentId_Language",
|
||||
schema: MigrationConstants.SchemaName,
|
||||
table: "Results");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Results_CvDocumentId_JobDocumentId",
|
||||
schema: MigrationConstants.SchemaName,
|
||||
table: "Results",
|
||||
columns: new[] { "CvDocumentId", "JobDocumentId" },
|
||||
unique: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user