Skip to content

Commit

Permalink
Now properly specifying and forcing migration of Postgres security if… (
Browse files Browse the repository at this point in the history
#283)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
csharpfritz and github-actions[bot] authored Nov 7, 2023
1 parent 9ebb4c7 commit 3b12623
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/TagzApp.Web/ServicesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using TagzApp.Providers.YouTubeChat;
using TagzApp.Storage.Postgres;
using TagzApp.Web.Data;
using TagzApp.Web.Migrations;
using TagzApp.Web.Services;

namespace TagzApp.Web;
Expand Down Expand Up @@ -138,9 +139,21 @@ public static void AddSecurityContext(this IServiceCollection services, IConfigu
services.AddDbContext<SecurityContext>(options =>
{
options.UseNpgsql(configuration.GetConnectionString("TagzAppSecurity"),
pg => pg.MigrationsAssembly("TagzApp.Storage.Postgres.Security"));
pg => pg.MigrationsAssembly(typeof(SecurityContextModelSnapshot).Assembly.FullName));
// "TagzApp.Storage.Postgres.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
});

var serviceLocator = services.BuildServiceProvider();
var securityContext = serviceLocator.GetRequiredService<SecurityContext>();

try
{
securityContext.Database.Migrate();
}
catch (Exception ex)
{
Console.WriteLine($"Error while migrating security context to Postgres: {ex}");
}
}
else if (!string.IsNullOrEmpty(configuration.GetConnectionString("SecurityContextConnection")))
{
Expand Down

0 comments on commit 3b12623

Please sign in to comment.