From f742ce31d0cb8f0f7f0498a01eee32a989d07db1 Mon Sep 17 00:00:00 2001 From: Nish26 Date: Sun, 21 Jan 2024 21:49:55 +0530 Subject: [PATCH 1/2] Don't create database automatically for entity framework based plugins Removed call for context.Database.EnsureCreatedAsync(); so that database is not created automatically. A new configuration flag 'AutoMigrate' is added with default value of false that can apply migrataions automatically. This will be useful for dev/ci-cd environments and to quickly spin up containers. Sql migration scripts should be used for actual production usecase. --- .config/identity-postgres-with-console-email.env | 1 + src/Pixel.Identity.Store.PostgreSQL/SqlConfigurator.cs | 3 ++- src/Pixel.Identity.Store.Sql.Shared/Worker.cs | 8 +++++++- src/Pixel.Identity.Store.SqlServer/SqlConfigurator.cs | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.config/identity-postgres-with-console-email.env b/.config/identity-postgres-with-console-email.env index 7cb8036..5bc5a24 100644 --- a/.config/identity-postgres-with-console-email.env +++ b/.config/identity-postgres-with-console-email.env @@ -3,6 +3,7 @@ #Admin account to create on initialize InitAdminUser=admin@pixel.com InitAdminUserPass=Admi9@pixel +AutoMigrate=true #Plugin configuration Plugins__Collection__0__Type=EmailSender diff --git a/src/Pixel.Identity.Store.PostgreSQL/SqlConfigurator.cs b/src/Pixel.Identity.Store.PostgreSQL/SqlConfigurator.cs index f2c024c..b43f455 100644 --- a/src/Pixel.Identity.Store.PostgreSQL/SqlConfigurator.cs +++ b/src/Pixel.Identity.Store.PostgreSQL/SqlConfigurator.cs @@ -37,7 +37,8 @@ public IdentityBuilder ConfigureIdentity(IConfiguration configuration, IServiceC return services.AddDbContext(options => { - options.UseNpgsql(configuration.GetConnectionString("PostgreServerConnection")); + options.UseNpgsql(configuration.GetConnectionString("PostgreServerConnection"), + x => x.MigrationsAssembly("Pixel.Identity.Store.PostgreSQL")); // Register the entity sets needed by OpenIddict. // Note: use the generic overload if you need diff --git a/src/Pixel.Identity.Store.Sql.Shared/Worker.cs b/src/Pixel.Identity.Store.Sql.Shared/Worker.cs index ebbe03e..3b92a89 100644 --- a/src/Pixel.Identity.Store.Sql.Shared/Worker.cs +++ b/src/Pixel.Identity.Store.Sql.Shared/Worker.cs @@ -35,7 +35,13 @@ public async Task StartAsync(CancellationToken cancellationToken) using var scope = this.serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - await context.Database.EnsureCreatedAsync(); + //Apply migrations if autoMigrate configuration is enabled. In production, migrations should be applied + //using sql scripts provided with release. This can be handy to quickly spin a container or in dev / ci-cd environments + if (bool.TryParse(configuration["AutoMigrate"] ?? "false", out bool autoMigrate) && autoMigrate) + { + await context.Database.MigrateAsync(); + logger.LogInformation("Entity framework migration was applied based on 'AutoMigrate' configuraation flag"); + } var applicationManager = scope.ServiceProvider.GetRequiredService(); diff --git a/src/Pixel.Identity.Store.SqlServer/SqlConfigurator.cs b/src/Pixel.Identity.Store.SqlServer/SqlConfigurator.cs index 3f04e39..dc14ed0 100644 --- a/src/Pixel.Identity.Store.SqlServer/SqlConfigurator.cs +++ b/src/Pixel.Identity.Store.SqlServer/SqlConfigurator.cs @@ -37,7 +37,8 @@ public IdentityBuilder ConfigureIdentity(IConfiguration configuration, IServiceC return services.AddDbContext(options => { - options.UseSqlServer(configuration.GetConnectionString("SqlServerConnection")); + options.UseSqlServer(configuration.GetConnectionString("SqlServerConnection"), + x => x.MigrationsAssembly("Pixel.Identity.Store.SqlServer")); // Register the entity sets needed by OpenIddict. // Note: use the generic overload if you need From 6841e5b985b2fe7879e5d7d09e9751cbf2da3c66 Mon Sep 17 00:00:00 2001 From: Nish26 Date: Sun, 21 Jan 2024 22:01:18 +0530 Subject: [PATCH 2/2] Wait upto 60 seconds for registration page after clicking register page link --- src/Pixel.Identity.UI.Tests/PageModels/RegisterPage.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Pixel.Identity.UI.Tests/PageModels/RegisterPage.cs b/src/Pixel.Identity.UI.Tests/PageModels/RegisterPage.cs index 2184b81..5283770 100644 --- a/src/Pixel.Identity.UI.Tests/PageModels/RegisterPage.cs +++ b/src/Pixel.Identity.UI.Tests/PageModels/RegisterPage.cs @@ -1,4 +1,5 @@ using Microsoft.Playwright; +using System.Threading; using System.Threading.Tasks; namespace Pixel.Identity.UI.Tests.PageModels @@ -23,6 +24,11 @@ public RegisterPage(IPage page) public async Task GoToAsync() { await page.ClickAsync("#registerPageLink"); + await page.WaitForURLAsync(new System.Text.RegularExpressions.Regex(".*/Account/Register/*"), new PageWaitForURLOptions() + { + WaitUntil = WaitUntilState.NetworkIdle, + Timeout = 60000 + }); } ///