Skip to content

Commit

Permalink
Merge pull request #104 from Nfactor26/optional-migration-and-no-auto…
Browse files Browse the repository at this point in the history
…-db-creation

Optional migration and no auto db creation
  • Loading branch information
Nfactor26 authored Jan 21, 2024
2 parents 2cf21b0 + 6841e5b commit e0e0ea4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .config/identity-postgres-with-console-email.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#Admin account to create on initialize
InitAdminUser=[email protected]
InitAdminUserPass=Admi9@pixel
AutoMigrate=true

#Plugin configuration
Plugins__Collection__0__Type=EmailSender
Expand Down
3 changes: 2 additions & 1 deletion src/Pixel.Identity.Store.PostgreSQL/SqlConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public IdentityBuilder ConfigureIdentity(IConfiguration configuration, IServiceC

return services.AddDbContext<ApplicationDbContext>(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
Expand Down
8 changes: 7 additions & 1 deletion src/Pixel.Identity.Store.Sql.Shared/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public async Task StartAsync(CancellationToken cancellationToken)
using var scope = this.serviceProvider.CreateScope();

var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
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<IOpenIddictApplicationManager>();

Expand Down
3 changes: 2 additions & 1 deletion src/Pixel.Identity.Store.SqlServer/SqlConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public IdentityBuilder ConfigureIdentity(IConfiguration configuration, IServiceC

return services.AddDbContext<ApplicationDbContext>(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
Expand Down
6 changes: 6 additions & 0 deletions src/Pixel.Identity.UI.Tests/PageModels/RegisterPage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Playwright;
using System.Threading;
using System.Threading.Tasks;

namespace Pixel.Identity.UI.Tests.PageModels
Expand All @@ -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
});
}

/// <summary>
Expand Down

0 comments on commit e0e0ea4

Please sign in to comment.