Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional migration and no auto db creation #104

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
[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
Loading