47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using StellaOps.Evidence.Core;
|
|
using StellaOps.Infrastructure.Postgres.Connections;
|
|
using System.Text.Json;
|
|
|
|
namespace StellaOps.Evidence.Persistence.Postgres;
|
|
|
|
/// <summary>
|
|
/// PostgreSQL (EF Core) implementation of <see cref="IEvidenceStore"/>.
|
|
/// Stores evidence records with content-addressed IDs and tenant isolation via RLS.
|
|
/// </summary>
|
|
public sealed partial class PostgresEvidenceStore : IEvidenceStore
|
|
{
|
|
private const int CommandTimeoutSeconds = 30;
|
|
|
|
private readonly EvidenceDataSource _dataSource;
|
|
private readonly string _tenantId;
|
|
private readonly ILogger<PostgresEvidenceStore> _logger;
|
|
|
|
private static readonly JsonSerializerOptions _jsonOptions = new()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
};
|
|
|
|
/// <summary>
|
|
/// Creates a new PostgreSQL evidence store for the specified tenant.
|
|
/// </summary>
|
|
/// <param name="dataSource">Evidence data source.</param>
|
|
/// <param name="tenantId">Tenant identifier for RLS.</param>
|
|
/// <param name="logger">Logger instance.</param>
|
|
public PostgresEvidenceStore(
|
|
EvidenceDataSource dataSource,
|
|
string tenantId,
|
|
ILogger<PostgresEvidenceStore> logger)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(dataSource);
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(tenantId);
|
|
ArgumentNullException.ThrowIfNull(logger);
|
|
|
|
_dataSource = dataSource;
|
|
_tenantId = tenantId;
|
|
_logger = logger;
|
|
}
|
|
|
|
private string GetSchemaName() => EvidenceDataSource.DefaultSchemaName;
|
|
}
|