feat(DatabaseInitializer): add database migration logic and clean up initialization process

This commit is contained in:
shiyu
2025-05-23 21:31:04 +08:00
parent 7932240bbb
commit 3feb71493f
4 changed files with 32 additions and 38 deletions

View File

@@ -38,7 +38,9 @@ public class AuthService(IDbContextFactory<MyDbContext> dbContextFactory, IConfi
var userCount = await context.Users.CountAsync();
if (userCount == 0)
{
var role = await context.Roles.FirstOrDefaultAsync(r => r.Id == 1);
user.RoleId = 1;
user.Role = role;
}
context.Users.Add(user);
await context.SaveChangesAsync();