feat(push): add service-owned firebase channels and delivery
Add push contracts, provider delivery and channel diagnostics. Link email channels to services and document migration and validation. Ref: IT-1074
This commit is contained in:
@@ -13,12 +13,10 @@ internal class EmailChannelEntityConfiguration : IEntityTypeConfiguration<EmailC
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Id).HasColumnName("id");
|
||||
|
||||
builder.Property(x => x.ServiceName)
|
||||
.HasColumnName("service_name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.HasIndex(x => new { x.ServiceName, x.Priority });
|
||||
builder.Property(x => x.ServiceId).HasColumnName("service_id").IsRequired();
|
||||
builder.HasOne(x => x.Service).WithMany().HasForeignKey(x => x.ServiceId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasIndex(x => new { x.ServiceId, x.Priority });
|
||||
|
||||
builder.Property(x => x.Priority).HasColumnName("priority");
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Configurations;
|
||||
|
||||
internal sealed class PushChannelEntityConfiguration : IEntityTypeConfiguration<PushChannelEntity>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<PushChannelEntity> builder)
|
||||
{
|
||||
builder.ToTable("push_channels");
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Id).HasColumnName("id");
|
||||
builder.Property(x => x.ServiceId).HasColumnName("service_id");
|
||||
builder.HasIndex(x => x.ServiceId).IsUnique();
|
||||
builder.HasOne(x => x.Service).WithMany().HasForeignKey(x => x.ServiceId).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.Property(x => x.FirebaseProjectId).HasColumnName("firebase_project_id").HasMaxLength(30).IsRequired();
|
||||
builder.Property(x => x.CredentialsJson).HasColumnName("credentials").HasColumnType("jsonb").IsRequired();
|
||||
builder.Property(x => x.IsActive).HasColumnName("is_active");
|
||||
builder.Property(x => x.Created).HasColumnName("created");
|
||||
builder.Property(x => x.Updated).HasColumnName("updated");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace HrynCo.NotificationService.DAL.EF.Configurations;
|
||||
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public sealed class PushDeliveryEntityConfiguration : IEntityTypeConfiguration<PushDeliveryEntity>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<PushDeliveryEntity> builder)
|
||||
{
|
||||
builder.ToTable("PushDeliveries");
|
||||
builder.HasKey(x => new { x.ServiceName, x.MessageId });
|
||||
builder.Property(x => x.ServiceName).HasMaxLength(128);
|
||||
builder.Property(x => x.Error).HasMaxLength(256);
|
||||
builder.HasIndex(x => x.CompletedAt);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ namespace HrynCo.NotificationService.DAL.EF.Entities;
|
||||
|
||||
internal class EmailChannelEntity : Entity
|
||||
{
|
||||
public required string ServiceName { get; set; }
|
||||
public Guid ServiceId { get; set; }
|
||||
public ServiceEntity Service { get; set; } = null!;
|
||||
public int Priority { get; set; }
|
||||
public EmailChannelType EmailChannelType { get; set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using HrynCo.DAL.Abstract.Entities;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Entities;
|
||||
|
||||
internal sealed class PushChannelEntity : Entity
|
||||
{
|
||||
public Guid ServiceId { get; set; }
|
||||
public ServiceEntity Service { get; set; } = null!;
|
||||
public required string FirebaseProjectId { get; set; }
|
||||
public required string CredentialsJson { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace HrynCo.NotificationService.DAL.EF.Entities;
|
||||
|
||||
public sealed class PushDeliveryEntity
|
||||
{
|
||||
public Guid MessageId { get; set; }
|
||||
public string ServiceName { get; set; } = "";
|
||||
public string? Error { get; set; }
|
||||
public bool InvalidRegistration { get; set; }
|
||||
public DateTimeOffset CompletedAt { get; set; }
|
||||
}
|
||||
+402
@@ -0,0 +1,402 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using HrynCo.NotificationService.DAL.EF;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
{
|
||||
[DbContext(typeof(NotificationDbContext))]
|
||||
[Migration("20261023223753_AddPushDeliveries")]
|
||||
partial class AddPushDeliveries
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<int?>("DailyLimit")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("daily_limit");
|
||||
|
||||
b.Property<int>("EmailChannelType")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("provider_type");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_active");
|
||||
|
||||
b.Property<int?>("MonthlyLimit")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("monthly_limit");
|
||||
|
||||
b.Property<int>("Priority")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("priority");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("service_name");
|
||||
|
||||
b.Property<string>("SettingsJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("settings");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.Property<int>("WarnThresholdPercent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("warn_threshold_percent");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceName", "Priority");
|
||||
|
||||
b.ToTable("email_channels", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelUsageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date")
|
||||
.HasColumnName("date");
|
||||
|
||||
b.Property<Guid>("ProviderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("provider_id");
|
||||
|
||||
b.Property<int>("SentCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sent_count");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProviderId", "Date")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("email_channel_usage", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<Guid>("Revision")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("revision");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Key")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("email_template_definitions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<Guid>("DefinitionId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("definition_id");
|
||||
|
||||
b.Property<string>("HtmlBody")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("html_body");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<Guid>("ServiceLanguageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_language_id");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("subject");
|
||||
|
||||
b.Property<string>("TextBody")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("text_body");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DefinitionId", "ServiceId");
|
||||
|
||||
b.HasIndex("DefinitionId", "ServiceLanguageId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("ServiceLanguageId", "ServiceId");
|
||||
|
||||
b.ToTable("email_templates", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushDeliveryEntity", b =>
|
||||
{
|
||||
b.Property<string>("ServiceName")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CompletedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Error")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<bool>("InvalidRegistration")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("ServiceName", "MessageId");
|
||||
|
||||
b.HasIndex("CompletedAt");
|
||||
|
||||
b.ToTable("PushDeliveries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<Guid>("Revision")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("revision");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("services", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("code");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Code")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("service_languages", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelUsageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", null)
|
||||
.WithMany("UsageRecords")
|
||||
.HasForeignKey("ProviderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsMany("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateVariableData", "Variables", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("EmailTemplateDefinitionEntityId");
|
||||
|
||||
b1.Property<int>("__synthesizedOrdinal")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b1.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasJsonPropertyName("name");
|
||||
|
||||
b1.Property<bool>("Required")
|
||||
.HasJsonPropertyName("required");
|
||||
|
||||
b1.HasKey("EmailTemplateDefinitionEntityId", "__synthesizedOrdinal");
|
||||
|
||||
b1.ToTable("email_template_definitions");
|
||||
|
||||
b1
|
||||
.ToJson("variables")
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("EmailTemplateDefinitionEntityId");
|
||||
});
|
||||
|
||||
b.Navigation("Service");
|
||||
|
||||
b.Navigation("Variables");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", "Definition")
|
||||
.WithMany("Languages")
|
||||
.HasForeignKey("DefinitionId", "ServiceId")
|
||||
.HasPrincipalKey("Id", "ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", "ServiceLanguage")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceLanguageId", "ServiceId")
|
||||
.HasPrincipalKey("Id", "ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Definition");
|
||||
|
||||
b.Navigation("ServiceLanguage");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany("Languages")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.Navigation("UsageRecords");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.Navigation("Languages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", b =>
|
||||
{
|
||||
b.Navigation("Languages");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPushDeliveries : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PushDeliveries",
|
||||
columns: table => new
|
||||
{
|
||||
MessageId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
ServiceName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
||||
Error = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||
InvalidRegistration = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CompletedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PushDeliveries", x => new { x.ServiceName, x.MessageId });
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PushDeliveries_CompletedAt",
|
||||
table: "PushDeliveries",
|
||||
column: "CompletedAt");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PushDeliveries");
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+411
@@ -0,0 +1,411 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using HrynCo.NotificationService.DAL.EF;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
{
|
||||
[DbContext(typeof(NotificationDbContext))]
|
||||
[Migration("20261024073202_LinkEmailChannelsToServices")]
|
||||
partial class LinkEmailChannelsToServices
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<int?>("DailyLimit")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("daily_limit");
|
||||
|
||||
b.Property<int>("EmailChannelType")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("provider_type");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_active");
|
||||
|
||||
b.Property<int?>("MonthlyLimit")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("monthly_limit");
|
||||
|
||||
b.Property<int>("Priority")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("priority");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<string>("SettingsJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("settings");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.Property<int>("WarnThresholdPercent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("warn_threshold_percent");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Priority");
|
||||
|
||||
b.ToTable("email_channels", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelUsageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date")
|
||||
.HasColumnName("date");
|
||||
|
||||
b.Property<Guid>("ProviderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("provider_id");
|
||||
|
||||
b.Property<int>("SentCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sent_count");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProviderId", "Date")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("email_channel_usage", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<Guid>("Revision")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("revision");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Key")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("email_template_definitions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<Guid>("DefinitionId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("definition_id");
|
||||
|
||||
b.Property<string>("HtmlBody")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("html_body");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<Guid>("ServiceLanguageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_language_id");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("subject");
|
||||
|
||||
b.Property<string>("TextBody")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("text_body");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DefinitionId", "ServiceId");
|
||||
|
||||
b.HasIndex("DefinitionId", "ServiceLanguageId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("ServiceLanguageId", "ServiceId");
|
||||
|
||||
b.ToTable("email_templates", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushDeliveryEntity", b =>
|
||||
{
|
||||
b.Property<string>("ServiceName")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CompletedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Error")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<bool>("InvalidRegistration")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("ServiceName", "MessageId");
|
||||
|
||||
b.HasIndex("CompletedAt");
|
||||
|
||||
b.ToTable("PushDeliveries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<Guid>("Revision")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("revision");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("services", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("code");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Code")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("service_languages", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelUsageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", null)
|
||||
.WithMany("UsageRecords")
|
||||
.HasForeignKey("ProviderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsMany("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateVariableData", "Variables", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("EmailTemplateDefinitionEntityId");
|
||||
|
||||
b1.Property<int>("__synthesizedOrdinal")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b1.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasJsonPropertyName("name");
|
||||
|
||||
b1.Property<bool>("Required")
|
||||
.HasJsonPropertyName("required");
|
||||
|
||||
b1.HasKey("EmailTemplateDefinitionEntityId", "__synthesizedOrdinal");
|
||||
|
||||
b1.ToTable("email_template_definitions");
|
||||
|
||||
b1
|
||||
.ToJson("variables")
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("EmailTemplateDefinitionEntityId");
|
||||
});
|
||||
|
||||
b.Navigation("Service");
|
||||
|
||||
b.Navigation("Variables");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", "Definition")
|
||||
.WithMany("Languages")
|
||||
.HasForeignKey("DefinitionId", "ServiceId")
|
||||
.HasPrincipalKey("Id", "ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", "ServiceLanguage")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceLanguageId", "ServiceId")
|
||||
.HasPrincipalKey("Id", "ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Definition");
|
||||
|
||||
b.Navigation("ServiceLanguage");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany("Languages")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.Navigation("UsageRecords");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.Navigation("Languages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", b =>
|
||||
{
|
||||
b.Navigation("Languages");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Migrations;
|
||||
|
||||
public partial class LinkEmailChannelsToServices : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// EF runs this whole migration in one transaction. Lock the source rows so a
|
||||
// concurrent rename or channel write cannot invalidate the verified mapping.
|
||||
migrationBuilder.Sql("""
|
||||
LOCK TABLE services IN SHARE ROW EXCLUSIVE MODE;
|
||||
LOCK TABLE email_channels IN ACCESS EXCLUSIVE MODE;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM email_channels c
|
||||
WHERE (SELECT count(*) FROM services s
|
||||
WHERE s.name = c.service_name
|
||||
OR (c.service_name = 'StoreMate-Prod' AND s.name = 'Invemory-Prod')) <> 1
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Email channel migration stopped: every legacy service name must have exactly one existing service (including the approved StoreMate-Prod -> Invemory-Prod alias). Resolve missing or ambiguous names before retrying.';
|
||||
END IF;
|
||||
END $$;
|
||||
ALTER TABLE email_channels ADD COLUMN service_id uuid;
|
||||
UPDATE email_channels c SET service_id = s.id
|
||||
FROM services s
|
||||
WHERE s.name = c.service_name
|
||||
OR (c.service_name = 'StoreMate-Prod' AND s.name = 'Invemory-Prod');
|
||||
ALTER TABLE email_channels ALTER COLUMN service_id SET NOT NULL;
|
||||
""");
|
||||
migrationBuilder.DropIndex("IX_email_channels_service_name_priority", "email_channels");
|
||||
migrationBuilder.DropColumn("service_name", "email_channels");
|
||||
migrationBuilder.CreateIndex("IX_email_channels_service_id_priority", "email_channels", new[] { "service_id", "priority" });
|
||||
migrationBuilder.AddForeignKey("FK_email_channels_services_service_id", "email_channels", "service_id",
|
||||
"services", principalColumn: "id", onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Restore current service names; historical names are intentionally not retained.
|
||||
migrationBuilder.Sql("""
|
||||
ALTER TABLE email_channels ADD COLUMN service_name character varying(100);
|
||||
UPDATE email_channels c SET service_name = s.name FROM services s WHERE s.id = c.service_id;
|
||||
ALTER TABLE email_channels ALTER COLUMN service_name SET NOT NULL;
|
||||
""");
|
||||
migrationBuilder.DropForeignKey("FK_email_channels_services_service_id", "email_channels");
|
||||
migrationBuilder.DropIndex("IX_email_channels_service_id_priority", "email_channels");
|
||||
migrationBuilder.DropColumn("service_id", "email_channels");
|
||||
migrationBuilder.CreateIndex("IX_email_channels_service_name_priority", "email_channels", new[] { "service_name", "priority" });
|
||||
}
|
||||
}
|
||||
+464
@@ -0,0 +1,464 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using HrynCo.NotificationService.DAL.EF;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
{
|
||||
[DbContext(typeof(NotificationDbContext))]
|
||||
[Migration("20261024080457_AddPushChannels")]
|
||||
partial class AddPushChannels
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<int?>("DailyLimit")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("daily_limit");
|
||||
|
||||
b.Property<int>("EmailChannelType")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("provider_type");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_active");
|
||||
|
||||
b.Property<int?>("MonthlyLimit")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("monthly_limit");
|
||||
|
||||
b.Property<int>("Priority")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("priority");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<string>("SettingsJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("settings");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.Property<int>("WarnThresholdPercent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("warn_threshold_percent");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Priority");
|
||||
|
||||
b.ToTable("email_channels", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelUsageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date")
|
||||
.HasColumnName("date");
|
||||
|
||||
b.Property<Guid>("ProviderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("provider_id");
|
||||
|
||||
b.Property<int>("SentCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sent_count");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProviderId", "Date")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("email_channel_usage", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<Guid>("Revision")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("revision");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Key")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("email_template_definitions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<Guid>("DefinitionId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("definition_id");
|
||||
|
||||
b.Property<string>("HtmlBody")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("html_body");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<Guid>("ServiceLanguageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_language_id");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("subject");
|
||||
|
||||
b.Property<string>("TextBody")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("text_body");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DefinitionId", "ServiceId");
|
||||
|
||||
b.HasIndex("DefinitionId", "ServiceLanguageId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("ServiceLanguageId", "ServiceId");
|
||||
|
||||
b.ToTable("email_templates", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushChannelEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("CredentialsJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("credentials");
|
||||
|
||||
b.Property<string>("FirebaseProjectId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("character varying(30)")
|
||||
.HasColumnName("firebase_project_id");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_active");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("push_channels", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushDeliveryEntity", b =>
|
||||
{
|
||||
b.Property<string>("ServiceName")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CompletedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Error")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<bool>("InvalidRegistration")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("ServiceName", "MessageId");
|
||||
|
||||
b.HasIndex("CompletedAt");
|
||||
|
||||
b.ToTable("PushDeliveries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<Guid>("Revision")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("revision");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("services", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("character varying(10)")
|
||||
.HasColumnName("code");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId", "Code")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("service_languages", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelUsageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", null)
|
||||
.WithMany("UsageRecords")
|
||||
.HasForeignKey("ProviderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsMany("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateVariableData", "Variables", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("EmailTemplateDefinitionEntityId");
|
||||
|
||||
b1.Property<int>("__synthesizedOrdinal")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b1.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasJsonPropertyName("name");
|
||||
|
||||
b1.Property<bool>("Required")
|
||||
.HasJsonPropertyName("required");
|
||||
|
||||
b1.HasKey("EmailTemplateDefinitionEntityId", "__synthesizedOrdinal");
|
||||
|
||||
b1.ToTable("email_template_definitions");
|
||||
|
||||
b1
|
||||
.ToJson("variables")
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("EmailTemplateDefinitionEntityId");
|
||||
});
|
||||
|
||||
b.Navigation("Service");
|
||||
|
||||
b.Navigation("Variables");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", "Definition")
|
||||
.WithMany("Languages")
|
||||
.HasForeignKey("DefinitionId", "ServiceId")
|
||||
.HasPrincipalKey("Id", "ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", "ServiceLanguage")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceLanguageId", "ServiceId")
|
||||
.HasPrincipalKey("Id", "ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Definition");
|
||||
|
||||
b.Navigation("ServiceLanguage");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushChannelEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany("Languages")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.Navigation("UsageRecords");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailTemplateDefinitionEntity", b =>
|
||||
{
|
||||
b.Navigation("Languages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", b =>
|
||||
{
|
||||
b.Navigation("Languages");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPushChannels : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "push_channels",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
service_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
firebase_project_id = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||
credentials = table.Column<string>(type: "jsonb", nullable: false),
|
||||
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
||||
created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
updated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_push_channels", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "FK_push_channels_services_service_id",
|
||||
column: x => x.service_id,
|
||||
principalTable: "services",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_push_channels_service_id",
|
||||
table: "push_channels",
|
||||
column: "service_id",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "push_channels");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,11 +53,9 @@ namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("priority");
|
||||
|
||||
b.Property<string>("ServiceName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("service_name");
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<string>("SettingsJson")
|
||||
.IsRequired()
|
||||
@@ -74,7 +72,7 @@ namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceName", "Priority");
|
||||
b.HasIndex("ServiceId", "Priority");
|
||||
|
||||
b.ToTable("email_channels", (string)null);
|
||||
});
|
||||
@@ -206,6 +204,74 @@ namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
b.ToTable("email_templates", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushChannelEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<string>("CredentialsJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("credentials");
|
||||
|
||||
b.Property<string>("FirebaseProjectId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("character varying(30)")
|
||||
.HasColumnName("firebase_project_id");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_active");
|
||||
|
||||
b.Property<Guid>("ServiceId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.Property<DateTimeOffset?>("Updated")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ServiceId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("push_channels", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushDeliveryEntity", b =>
|
||||
{
|
||||
b.Property<string>("ServiceName")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CompletedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Error")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<bool>("InvalidRegistration")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("ServiceName", "MessageId");
|
||||
|
||||
b.HasIndex("CompletedAt");
|
||||
|
||||
b.ToTable("PushDeliveries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -273,6 +339,17 @@ namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
b.ToTable("service_languages", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelUsageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.EmailChannelEntity", null)
|
||||
@@ -342,6 +419,17 @@ namespace HrynCo.NotificationService.DAL.EF.Migrations
|
||||
b.Navigation("ServiceLanguage");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.PushChannelEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HrynCo.NotificationService.DAL.EF.Entities.ServiceLanguageEntity", b =>
|
||||
{
|
||||
b.HasOne("HrynCo.NotificationService.DAL.EF.Entities.ServiceEntity", "Service")
|
||||
|
||||
@@ -11,6 +11,7 @@ public class NotificationDbContext : DbContext
|
||||
}
|
||||
|
||||
internal DbSet<ServiceLanguageEntity> ServiceLanguages => Set<ServiceLanguageEntity>();
|
||||
internal DbSet<PushChannelEntity> PushChannels => Set<PushChannelEntity>();
|
||||
internal DbSet<ServiceEntity> Services => Set<ServiceEntity>();
|
||||
internal DbSet<EmailTemplateDefinitionEntity> TemplateDefinitions => Set<EmailTemplateDefinitionEntity>();
|
||||
internal DbSet<EmailTemplateEntity> Templates => Set<EmailTemplateEntity>();
|
||||
|
||||
@@ -8,9 +8,10 @@ internal sealed class NotificationDbContextFactory : IDesignTimeDbContextFactory
|
||||
public NotificationDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<NotificationDbContext>()
|
||||
.UseNpgsql("Host=localhost;Port=5432;Database=notification_service;Username=postgres;Password=postgres")
|
||||
.UseNpgsql(Environment.GetEnvironmentVariable("App__ConnectionString")
|
||||
?? "Host=localhost;Port=5432;Database=notification_service;Username=postgres;Password=postgres")
|
||||
.Options;
|
||||
|
||||
return new NotificationDbContext(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ internal sealed class EmailChannelRepository : NotificationBaseRepository<EmailC
|
||||
|
||||
public async Task<IReadOnlyList<EmailChannel>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
var entities = await EfRepository.Get().ToListAsync(ct);
|
||||
var entities = await EfRepository.Get().AsNoTracking().Include(x => x.Service).ToListAsync(ct);
|
||||
|
||||
return entities.Select(MapToDomain).ToList();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<EmailChannel>> GetByServiceAsync(string serviceName, CancellationToken ct = default)
|
||||
public async Task<IReadOnlyList<EmailChannel>> GetByServiceAsync(Guid serviceId, CancellationToken ct = default)
|
||||
{
|
||||
var entities = await EfRepository.Get(x => x.ServiceName == serviceName)
|
||||
var entities = await EfRepository.Get(x => x.ServiceId == serviceId).Include(x => x.Service)
|
||||
.OrderBy(x => x.Priority)
|
||||
.ToListAsync(ct);
|
||||
|
||||
@@ -32,8 +32,8 @@ internal sealed class EmailChannelRepository : NotificationBaseRepository<EmailC
|
||||
public async Task<IReadOnlyList<ChannelWithUsage>> GetAllWithUsageSummaryAsync(
|
||||
DateOnly today, CancellationToken ct = default)
|
||||
{
|
||||
var rows = await EfRepository.Get()
|
||||
.OrderBy(c => c.ServiceName)
|
||||
var rows = await EfRepository.Get().AsNoTracking().Include(c => c.Service)
|
||||
.OrderBy(c => c.Service.Name)
|
||||
.ThenBy(c => c.Priority)
|
||||
.Select(c => new
|
||||
{
|
||||
@@ -54,7 +54,7 @@ internal sealed class EmailChannelRepository : NotificationBaseRepository<EmailC
|
||||
|
||||
public async Task<EmailChannel?> GetByIdAsync(Guid id, CancellationToken ct = default)
|
||||
{
|
||||
EmailChannelEntity? entity = await EfRepository.Get().AsNoTracking().SingleOrDefaultAsync(c => c.Id == id, ct);
|
||||
EmailChannelEntity? entity = await EfRepository.Get().AsNoTracking().Include(c => c.Service).SingleOrDefaultAsync(c => c.Id == id, ct);
|
||||
return entity is null ? null : MapToDomain(entity);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ internal sealed class EmailChannelRepository : NotificationBaseRepository<EmailC
|
||||
return new EmailChannel
|
||||
{
|
||||
Id = e.Id,
|
||||
ServiceName = e.ServiceName,
|
||||
ServiceId = e.ServiceId,
|
||||
ServiceName = e.Service.Name,
|
||||
Priority = e.Priority,
|
||||
EmailChannelType = e.EmailChannelType,
|
||||
Settings = DeserializeSettings(e.EmailChannelType, e.SettingsJson),
|
||||
@@ -97,7 +98,7 @@ internal sealed class EmailChannelRepository : NotificationBaseRepository<EmailC
|
||||
return new EmailChannelEntity
|
||||
{
|
||||
Id = p.Id,
|
||||
ServiceName = p.ServiceName,
|
||||
ServiceId = p.ServiceId,
|
||||
Priority = p.Priority,
|
||||
EmailChannelType = p.EmailChannelType,
|
||||
SettingsJson = JsonSerializer.Serialize(p.Settings, p.Settings.GetType()),
|
||||
|
||||
@@ -38,8 +38,7 @@ internal sealed class NotificationServiceRepository(NotificationDbContext db, Te
|
||||
return;
|
||||
if (service.Revision != revision)
|
||||
throw new EmailTemplateWriteException("The service revision changed. Read it again before deleting.");
|
||||
if (await db.TemplateDefinitions.AnyAsync(d => d.ServiceId == id, ct))
|
||||
throw new EmailTemplateWriteException("Remove every template definition before deleting this service, including definitions without translations.");
|
||||
await EnsureServiceIsEmptyAsync(id, ct);
|
||||
db.ServiceLanguages.RemoveRange(service.Languages);
|
||||
db.Services.Remove(service);
|
||||
removed = true;
|
||||
@@ -47,6 +46,14 @@ internal sealed class NotificationServiceRepository(NotificationDbContext db, Te
|
||||
return removed;
|
||||
}
|
||||
|
||||
private async Task EnsureServiceIsEmptyAsync(Guid id, CancellationToken ct)
|
||||
{
|
||||
if (await db.TemplateDefinitions.AnyAsync(d => d.ServiceId == id, ct))
|
||||
throw new EmailTemplateWriteException("Remove every template definition before deleting this service, including definitions without translations.");
|
||||
if (await db.Providers.AnyAsync(c => c.ServiceId == id, ct) || await db.PushChannels.AnyAsync(c => c.ServiceId == id, ct))
|
||||
throw new EmailTemplateWriteException("Reassign or remove every notification channel before deleting this service.");
|
||||
}
|
||||
|
||||
public Task SaveAsync(NotificationServiceInfo model, bool isNew, CancellationToken ct = default) => mutations.ExecuteAsync(async () =>
|
||||
{
|
||||
Validate(model);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
using HrynCo.NotificationService.DAL.Abstract.PushChannels;
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HrynCo.NotificationService.DAL.EF.Repositories;
|
||||
|
||||
internal sealed class PushChannelRepository(NotificationDbContext db, TemplateMutationRunner mutations) : IPushChannelRepository
|
||||
{
|
||||
public async Task<IReadOnlyList<PushChannel>> GetAllAsync(CancellationToken ct = default) =>
|
||||
await ReadModels().OrderBy(c => c.ServiceName).ToListAsync(ct);
|
||||
|
||||
public Task<PushChannel?> GetByIdAsync(Guid id, CancellationToken ct = default) =>
|
||||
ReadModels().SingleOrDefaultAsync(c => c.Id == id, ct);
|
||||
|
||||
public Task<PushChannel?> GetActiveForServiceAsync(Guid serviceId, CancellationToken ct = default) =>
|
||||
ReadModels().SingleOrDefaultAsync(c => c.ServiceId == serviceId && c.IsActive, ct);
|
||||
|
||||
public Task<string?> GetCredentialsAsync(Guid id, CancellationToken ct = default) =>
|
||||
db.PushChannels.AsNoTracking().Where(c => c.Id == id).Select(c => c.CredentialsJson).SingleOrDefaultAsync(ct);
|
||||
|
||||
public Task SaveAsync(PushChannel channel, string credentialsJson, bool isNew, CancellationToken ct = default) =>
|
||||
mutations.ExecuteAsync(async () =>
|
||||
{
|
||||
await ValidateServiceAsync(channel, ct);
|
||||
var entity = await LoadForSaveAsync(channel.Id, isNew, ct);
|
||||
entity.ServiceId = channel.ServiceId;
|
||||
entity.FirebaseProjectId = channel.FirebaseProjectId;
|
||||
entity.CredentialsJson = credentialsJson;
|
||||
entity.IsActive = channel.IsActive;
|
||||
entity.Updated = isNew ? null : DateTimeOffset.UtcNow;
|
||||
channel.Id = entity.Id;
|
||||
}, ct);
|
||||
|
||||
private async Task ValidateServiceAsync(PushChannel channel, CancellationToken ct)
|
||||
{
|
||||
if (!await db.Services.AnyAsync(s => s.Id == channel.ServiceId, ct))
|
||||
throw new PushChannelWriteException("Select an existing service.", false);
|
||||
if (await db.PushChannels.AnyAsync(c => c.ServiceId == channel.ServiceId && c.Id != channel.Id, ct))
|
||||
throw new PushChannelWriteException("This service already has a push channel. Edit that channel instead.");
|
||||
}
|
||||
|
||||
private async Task<PushChannelEntity> LoadForSaveAsync(Guid id, bool isNew, CancellationToken ct)
|
||||
{
|
||||
if (!isNew)
|
||||
return await db.PushChannels.SingleOrDefaultAsync(c => c.Id == id, ct)
|
||||
?? throw new PushChannelWriteException("The push channel no longer exists. Reload the list.");
|
||||
var entity = new PushChannelEntity
|
||||
{
|
||||
Id = id, FirebaseProjectId = string.Empty, CredentialsJson = "{}", Created = DateTimeOffset.UtcNow
|
||||
};
|
||||
db.PushChannels.Add(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private IQueryable<PushChannel> ReadModels() => db.PushChannels.AsNoTracking().Select(c => new PushChannel
|
||||
{
|
||||
Id = c.Id, ServiceId = c.ServiceId, ServiceName = c.Service.Name,
|
||||
FirebaseProjectId = c.FirebaseProjectId, IsActive = c.IsActive, Created = c.Created, Updated = c.Updated
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace HrynCo.NotificationService.DAL.EF.Repositories;
|
||||
|
||||
using HrynCo.NotificationService.DAL.Abstract.Push;
|
||||
using HrynCo.NotificationService.DAL.EF.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public sealed class PushDeliveryRepository(NotificationDbContext db) : IPushDeliveryRepository
|
||||
{
|
||||
public async Task<PushDeliveryOutcome> DeliverOnceAsync(Guid messageId, string serviceName,
|
||||
Func<CancellationToken, Task<PushDeliveryOutcome>> deliver, CancellationToken cancellationToken)
|
||||
{
|
||||
// Thirty days exceeds the maximum payload lifetime; old replays cannot send expired data.
|
||||
var cutoff = DateTimeOffset.UtcNow.AddDays(-30);
|
||||
await db.Set<PushDeliveryEntity>().Where(x => x.CompletedAt < cutoff).ExecuteDeleteAsync(cancellationToken);
|
||||
await using var transaction = await db.Database.BeginTransactionAsync(cancellationToken);
|
||||
var identity = $"{serviceName}:{messageId:D}";
|
||||
await db.Database.ExecuteSqlInterpolatedAsync(
|
||||
$"SELECT pg_advisory_xact_lock(hashtextextended({identity}, 1074))", cancellationToken);
|
||||
var previous = await db.Set<PushDeliveryEntity>().AsNoTracking()
|
||||
.SingleOrDefaultAsync(x => x.MessageId == messageId && x.ServiceName == serviceName, cancellationToken);
|
||||
if (previous is not null)
|
||||
return new PushDeliveryOutcome(previous.Error, previous.InvalidRegistration);
|
||||
|
||||
// One bounded provider call while holding this message's lock prevents concurrent sends.
|
||||
// A crash after FCM accepts still requires client-side message-id deduplication.
|
||||
var outcome = await deliver(cancellationToken);
|
||||
db.Add(new PushDeliveryEntity
|
||||
{
|
||||
MessageId = messageId, ServiceName = serviceName, Error = outcome.Error,
|
||||
InvalidRegistration = outcome.InvalidRegistration, CompletedAt = DateTimeOffset.UtcNow
|
||||
});
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
await transaction.CommitAsync(cancellationToken);
|
||||
return outcome;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public static class ServiceCollectionExtensions
|
||||
options.UseNpgsql(connectionString));
|
||||
|
||||
services.AddScoped<TemplateMutationRunner>();
|
||||
services.AddScoped<HrynCo.NotificationService.DAL.Abstract.PushChannels.IPushChannelRepository, PushChannelRepository>();
|
||||
services.AddScoped<HrynCo.NotificationService.DAL.Abstract.Push.IPushDeliveryRepository, PushDeliveryRepository>();
|
||||
services.AddScoped<INotificationServiceRepository, NotificationServiceRepository>();
|
||||
services.AddScoped<IEmailTemplateRepository, EmailTemplateRepository>();
|
||||
services.AddScoped<IEmailTemplateDefinitionRepository, EmailTemplateRepository>();
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
setlocal DisableDelayedExpansion
|
||||
set "NOTIFICATION_EF_DIR=%~dp0"
|
||||
powershell.exe -NoProfile -Command "$ErrorActionPreference = 'Stop'; Set-Location -LiteralPath $env:NOTIFICATION_EF_DIR; $config = Get-Content -LiteralPath '..\HrynCo.NotificationService.Web\appsettings.Development.json' -Raw | ConvertFrom-Json; $connection = New-Object System.Data.Common.DbConnectionStringBuilder; $connection.set_ConnectionString($config.App.ConnectionString); if ([string]$connection.get_Item('Host') -notin @('localhost', '127.0.0.1', '::1') -or [string]::IsNullOrWhiteSpace([string]$connection.get_Item('Database'))) { throw 'Refusing update: Development configuration must specify a loopback host and a database name.' }; $env:App__ConnectionString = $connection.get_ConnectionString(); dotnet ef database update --project 'HrynCo.NotificationService.DAL.EF.csproj' --configuration Release; exit $LASTEXITCODE"
|
||||
exit /b %ERRORLEVEL%
|
||||
Reference in New Issue
Block a user