Skip to content

Commit 34b8228

Browse files
committed
Adds licensing data store
Adds data store and entities required for persisting licensing and throughput data. This includes adding new tables for licensing metadata, throughput endpoints, and daily throughput data, as well as configurations and a data store implementation to interact with these tables.
1 parent aa63479 commit 34b8228

21 files changed

+1331
-19
lines changed

src/ProjectReferences.Persisters.Primary.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
<ItemGroup Label="Persisters">
44
<ProjectReference Include="..\ServiceControl.Persistence.RavenDB\ServiceControl.Persistence.RavenDB.csproj" ReferenceOutputAssembly="false" Private="false" />
5-
<ProjectReference Include="..\ServiceControl.Persistence.Sql\ServiceControl.Persistence.Sql.csproj" ReferenceOutputAssembly="false" Private="false" />
5+
<ProjectReference Include="..\ServiceControl.Persistence.Sql\ServiceControl.Persistence.Sql.SqlServer.csproj" ReferenceOutputAssembly="false" Private="false" />
6+
<ProjectReference Include="..\ServiceControl.Persistence.Sql\ServiceControl.Persistence.Sql.PostgreSQL.csproj" ReferenceOutputAssembly="false" Private="false" />
7+
<ProjectReference Include="..\ServiceControl.Persistence.Sql\ServiceControl.Persistence.Sql.MySQL.csproj" ReferenceOutputAssembly="false" Private="false" />
68
</ItemGroup>
79

810
</Project>

src/ServiceControl.Persistence.Sql.Core/Abstractions/BasePersistence.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace ServiceControl.Persistence.Sql.Core.Abstractions;
66
using ServiceControl.Persistence.UnitOfWork;
77
using Implementation;
88
using Implementation.UnitOfWork;
9+
using Particular.LicensingComponent.Persistence;
910

1011
public abstract class BasePersistence
1112
{
@@ -37,5 +38,6 @@ protected static void RegisterDataStores(IServiceCollection services, bool maint
3738
services.AddSingleton<INotificationsManager, NotificationsManager>();
3839
services.AddSingleton<IIngestionUnitOfWorkFactory, IngestionUnitOfWorkFactory>();
3940
services.AddSingleton<IErrorMessageDataStore, ErrorMessageDataStore>();
41+
services.AddSingleton<ILicensingDataStore, LicensingDataStore>();
4042
}
4143
}

src/ServiceControl.Persistence.Sql.Core/DbContexts/ServiceControlDbContextBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ protected ServiceControlDbContextBase(DbContextOptions options) : base(options)
2929
public DbSet<GroupCommentEntity> GroupComments { get; set; }
3030
public DbSet<RetryBatchNowForwardingEntity> RetryBatchNowForwarding { get; set; }
3131
public DbSet<NotificationsSettingsEntity> NotificationsSettings { get; set; }
32+
public DbSet<LicensingMetadataEntity> LicensingMetadata { get; set; }
33+
public DbSet<ThroughputEndpointEntity> Endpoints { get; set; }
34+
public DbSet<DailyThroughputEntity> Throughput { get; set; }
3235

3336
protected override void OnModelCreating(ModelBuilder modelBuilder)
3437
{
@@ -53,6 +56,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
5356
modelBuilder.ApplyConfiguration(new GroupCommentConfiguration());
5457
modelBuilder.ApplyConfiguration(new RetryBatchNowForwardingConfiguration());
5558
modelBuilder.ApplyConfiguration(new NotificationsSettingsConfiguration());
59+
modelBuilder.ApplyConfiguration(new LicensingMetadataEntityConfiguration());
60+
modelBuilder.ApplyConfiguration(new ThroughputEndpointConfiguration());
61+
modelBuilder.ApplyConfiguration(new DailyThroughputConfiguration());
5662

5763
OnModelCreatingProvider(modelBuilder);
5864
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ServiceControl.Persistence.Sql.Core.Entities;
2+
3+
public class DailyThroughputEntity
4+
{
5+
public int Id { get; set; }
6+
public required string EndpointName { get; set; }
7+
public required string ThroughputSource { get; set; }
8+
public required DateOnly Date { get; set; }
9+
public required long MessageCount { get; set; }
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ServiceControl.Persistence.Sql.Core.Entities;
2+
3+
public class LicensingMetadataEntity
4+
{
5+
public int Id { get; set; }
6+
public required string Key { get; set; }
7+
public required string Data { get; set; }
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace ServiceControl.Persistence.Sql.Core.Entities;
2+
3+
public class ThroughputEndpointEntity
4+
{
5+
public int Id { get; set; }
6+
public required string EndpointName { get; set; }
7+
public required string ThroughputSource { get; set; }
8+
public string? SanitizedEndpointName { get; set; }
9+
public string? EndpointIndicators { get; set; }
10+
public string? UserIndicator { get; set; }
11+
public string? Scope { get; set; }
12+
public DateOnly LastCollectedData { get; set; }
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace ServiceControl.Persistence.Sql.Core.EntityConfigurations;
2+
3+
using Entities;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
6+
7+
class DailyThroughputConfiguration : IEntityTypeConfiguration<DailyThroughputEntity>
8+
{
9+
public void Configure(EntityTypeBuilder<DailyThroughputEntity> builder)
10+
{
11+
builder.ToTable("DailyThroughput")
12+
.HasIndex(e => new
13+
{
14+
e.EndpointName,
15+
e.ThroughputSource,
16+
e.Date
17+
}, "UC_DailyThroughput_EndpointName_ThroughputSource_Date")
18+
.IsUnique();
19+
builder.HasKey(e => e.Id);
20+
builder.Property(e => e.EndpointName)
21+
.IsRequired()
22+
.HasMaxLength(200);
23+
builder.Property(e => e.ThroughputSource)
24+
.IsRequired()
25+
.HasMaxLength(50);
26+
builder.Property(e => e.Date)
27+
.IsRequired();
28+
builder.Property(e => e.MessageCount)
29+
.IsRequired();
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace ServiceControl.Persistence.Sql.Core.EntityConfigurations;
2+
3+
using Entities;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
6+
7+
class LicensingMetadataEntityConfiguration : IEntityTypeConfiguration<LicensingMetadataEntity>
8+
{
9+
public void Configure(EntityTypeBuilder<LicensingMetadataEntity> builder)
10+
{
11+
builder.ToTable("LicensingMetadata")
12+
.HasIndex(e => e.Key)
13+
.IsUnique();
14+
builder.HasKey(e => e.Id);
15+
builder.Property(e => e.Key)
16+
.IsRequired()
17+
.HasMaxLength(200);
18+
builder.Property(e => e.Data)
19+
.IsRequired()
20+
.HasMaxLength(2000);
21+
}
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace ServiceControl.Persistence.Sql.Core.EntityConfigurations;
2+
3+
using Entities;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
6+
7+
class ThroughputEndpointConfiguration : IEntityTypeConfiguration<ThroughputEndpointEntity>
8+
{
9+
public void Configure(EntityTypeBuilder<ThroughputEndpointEntity> builder)
10+
{
11+
builder.ToTable("ThroughputEndpoint")
12+
.HasIndex(e => new
13+
{
14+
e.EndpointName,
15+
e.ThroughputSource
16+
}, "UC_ThroughputEndpoint_EndpointName_ThroughputSource")
17+
.IsUnique();
18+
builder.HasKey(e => e.Id);
19+
builder.Property(e => e.EndpointName)
20+
.IsRequired()
21+
.HasMaxLength(200);
22+
builder.Property(e => e.ThroughputSource)
23+
.IsRequired()
24+
.HasMaxLength(50);
25+
26+
builder.Property(e => e.SanitizedEndpointName);
27+
builder.Property(e => e.EndpointIndicators);
28+
builder.Property(e => e.UserIndicator);
29+
builder.Property(e => e.Scope);
30+
builder.Property(e => e.LastCollectedData);
31+
}
32+
}

0 commit comments

Comments
 (0)