Files
git.stella-ops.org/src/__Libraries/StellaOps.ReachGraph.Persistence/PostgresReachGraphRepository.Delete.cs

38 lines
1.2 KiB
C#

// Licensed to StellaOps under the BUSL-1.1 license.
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using StellaOps.ReachGraph.Persistence.Postgres;
namespace StellaOps.ReachGraph.Persistence;
public sealed partial class PostgresReachGraphRepository
{
/// <inheritdoc />
public async Task<bool> DeleteAsync(
string digest,
string tenantId,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrEmpty(digest);
ArgumentException.ThrowIfNullOrEmpty(tenantId);
await using var connection = await _dataSource
.OpenConnectionAsync(tenantId, "writer", cancellationToken)
.ConfigureAwait(false);
await using var dbContext = ReachGraphDbContextFactory.Create(connection, CommandTimeoutSeconds, GetSchemaName());
var affected = await dbContext.Subgraphs
.Where(s => s.Digest == digest && s.TenantId == tenantId)
.ExecuteDeleteAsync(cancellationToken)
.ConfigureAwait(false);
if (affected > 0)
{
_logger.LogInformation("Deleted reachability graph {Digest}", digest);
return true;
}
return false;
}
}