Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
meysamhadeli committed Jun 1, 2023
2 parents f2490e2 + ee2936f commit 1a6a9b5
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 237 deletions.
4 changes: 0 additions & 4 deletions src/BuildingBlocks/EFCore/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Linq.Expressions;
using BuildingBlocks.Core.Model;
using BuildingBlocks.PersistMessageProcessor.Data;
using BuildingBlocks.Web;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down Expand Up @@ -114,9 +113,6 @@ private static async Task MigrateDatabaseAsync<TContext>(IServiceProvider servic
{
using var scope = serviceProvider.CreateScope();

var persistMessageContext = scope.ServiceProvider.GetRequiredService<PersistMessageDbContext>();
await persistMessageContext.Database.MigrateAsync();

var context = scope.ServiceProvider.GetRequiredService<TContext>();
await context.Database.MigrateAsync();
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ public override async Task<int> SaveChangesAsync(CancellationToken cancellationT
}
}

public void CreatePersistMessageTable()
{
if (Database.GetPendingMigrations().Any())
{
throw new InvalidOperationException("Cannot create table if there are pending migrations.");
}

string createTableSql = @"
create table if not exists persist_message (
id uuid not null,
data_type text,
data text,
created timestamp with time zone not null,
retry_count integer not null,
message_status text not null default 'InProgress'::text,
delivery_type text not null default 'Outbox'::text,
version bigint not null,
constraint pk_persist_message primary key (id)
)";

Database.ExecuteSqlRaw(createTableSql);
}

private void OnBeforeSaving()
{
try
Expand Down
2 changes: 0 additions & 2 deletions src/BuildingBlocks/PersistMessageProcessor/Data/readme.md

This file was deleted.

25 changes: 9 additions & 16 deletions src/BuildingBlocks/PersistMessageProcessor/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ public static IServiceCollection AddPersistMessageProcessor(this IServiceCollect
.UseSnakeCaseNamingConvention();
});

services.AddScoped<IPersistMessageDbContext>(provider => provider.GetService<PersistMessageDbContext>());
services.AddScoped<IPersistMessageDbContext>(provider =>
{
var persistMessageDbContext = provider.GetRequiredService<PersistMessageDbContext>();

persistMessageDbContext.Database.EnsureCreated();
persistMessageDbContext.CreatePersistMessageTable();

return persistMessageDbContext;
});

services.AddScoped<IPersistMessageProcessor, PersistMessageProcessor>();

Expand All @@ -41,19 +49,4 @@ public static IServiceCollection AddPersistMessageProcessor(this IServiceCollect

return services;
}

public static IApplicationBuilder UseMigrationPersistMessage<TContext>(this IApplicationBuilder app,
IWebHostEnvironment env)
where TContext : DbContext, IPersistMessageDbContext
{
using var scope = app.ApplicationServices.CreateScope();

var persistMessageContext = scope.ServiceProvider.GetRequiredService<PersistMessageDbContext>();
persistMessageContext.Database.Migrate();

var context = scope.ServiceProvider.GetRequiredService<TContext>();
context.Database.Migrate();

return app;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace Booking.Extensions.Infrastructure;

using BuildingBlocks.PersistMessageProcessor.Data;

public static class InfrastructureExtensions
{
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
Expand Down Expand Up @@ -97,7 +95,6 @@ public static WebApplication UseInfrastructure(this WebApplication app)
});
app.UseCorrelationId();
app.UseHttpMetrics();
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
app.UseCustomHealthCheck();
app.MapMetrics();
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public static WebApplication UseInfrastructure(this WebApplication app)
});
app.UseCorrelationId();
app.UseHttpMetrics();
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
app.UseMigration<FlightDbContext>(env);
app.MapMetrics();
app.UseCustomHealthCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public static WebApplication UseInfrastructure(this WebApplication app)
{
options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest;
});
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
app.UseMigration<IdentityContext>(env);
app.UseCorrelationId();
app.UseHttpMetrics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

namespace Passenger.Extensions.Infrastructure;

using BuildingBlocks.PersistMessageProcessor.Data;

public static class InfrastructureExtensions
{
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
Expand Down Expand Up @@ -94,7 +92,6 @@ public static WebApplication UseInfrastructure(this WebApplication app)
{
options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest;
});
app.UseMigrationPersistMessage<PersistMessageDbContext>(env);
app.UseMigration<PassengerDbContext>(env);
app.UseCorrelationId();
app.UseHttpMetrics();
Expand Down

0 comments on commit 1a6a9b5

Please sign in to comment.