// 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 { /// public async Task 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; } }