mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 10:43:13 +00:00
fix: distinguish uplift request key conflicts
This commit is contained in:
parent
8af9ad076f
commit
0ca9b767ed
3 changed files with 18 additions and 3 deletions
|
|
@ -547,9 +547,7 @@ namespace SeaHaven.DataServices.Implementation
|
|||
{
|
||||
var number = exceptionType.GetProperty("Number")?.GetValue(databaseException) as int?;
|
||||
return number is 2601 or 2627
|
||||
&& databaseException.Message.Contains(
|
||||
"IX_DispatchUpliftRequests_DispatchId",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
&& IsActiveDispatchIndexViolationMessage(databaseException.Message);
|
||||
}
|
||||
|
||||
if (provider?.Contains("Sqlite", StringComparison.OrdinalIgnoreCase) == true
|
||||
|
|
@ -576,6 +574,12 @@ namespace SeaHaven.DataServices.Implementation
|
|||
return false;
|
||||
}
|
||||
|
||||
internal static bool IsActiveDispatchIndexViolationMessage(string message)
|
||||
{
|
||||
const string activeDispatchIndex = "'IX_DispatchUpliftRequests_DispatchId'";
|
||||
return message.Contains(activeDispatchIndex, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task<T> ExecuteWorkOrderMutationAsync<T>(
|
||||
int workOrderId,
|
||||
Func<CancellationToken, Task<T>> work,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Api.SeaHavenIndustries.Tests")]
|
||||
[assembly: InternalsVisibleTo("SeaHavenIndustries.Tests")]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@ namespace SeaHavenIndustries.Tests;
|
|||
|
||||
public sealed class UpliftDataServiceTransactionTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Cannot insert duplicate key row with unique index 'IX_DispatchUpliftRequests_DispatchId'.", true)]
|
||||
[InlineData("Cannot insert duplicate key row with unique index 'IX_DispatchUpliftRequests_DispatchId_RequestKey'.", false)]
|
||||
public void IsActiveDispatchIndexViolationMessage_MatchesOnlyTheActiveDispatchIndex(
|
||||
string message,
|
||||
bool expected)
|
||||
{
|
||||
Assert.Equal(expected, UpliftDataService.IsActiveDispatchIndexViolationMessage(message));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SaveChangesAsync_ActiveUpliftOnSameDispatch_MapsConcurrentInsertConflict()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue