Files
git.stella-ops.org/src/Notify/__Libraries/StellaOps.Notify.Persistence/Postgres/NotifyDataSource.cs

50 lines
1.7 KiB
C#

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Npgsql;
using StellaOps.Infrastructure.Postgres.Connections;
using StellaOps.Infrastructure.Postgres.Options;
using StellaOps.Notify.Persistence.Postgres.Models;
namespace StellaOps.Notify.Persistence.Postgres;
/// <summary>
/// PostgreSQL data source for the Notify module.
/// Manages connections with tenant context for notifications and delivery tracking.
/// </summary>
public sealed class NotifyDataSource : DataSourceBase
{
/// <summary>
/// Default schema name for Notify tables.
/// </summary>
public const string DefaultSchemaName = "notify";
/// <summary>
/// Creates a new Notify data source.
/// </summary>
public NotifyDataSource(IOptions<PostgresOptions> options, ILogger<NotifyDataSource> logger)
: base(CreateOptions(options.Value), logger)
{
}
/// <inheritdoc />
protected override string ModuleName => "Notify";
/// <inheritdoc />
protected override void ConfigureDataSourceBuilder(NpgsqlDataSourceBuilder builder)
{
// Register PostgreSQL enum type mappings so Npgsql sends enum values natively
// instead of text, matching the notify.channel_type and notify.delivery_status DB types.
builder.MapEnum<ChannelType>(DefaultSchemaName + ".channel_type");
builder.MapEnum<DeliveryStatus>(DefaultSchemaName + ".delivery_status");
}
private static PostgresOptions CreateOptions(PostgresOptions baseOptions)
{
if (string.IsNullOrWhiteSpace(baseOptions.SchemaName))
{
baseOptions.SchemaName = DefaultSchemaName;
}
return baseOptions;
}
}