dex-backend
dex-backend copied to clipboard
Update the seed to check to update roles & users
Describe the bug Users are not updated in when something changes in the seed and the application does not instantiate the database. So the seed will only execute when there are no users stored in the database. There already is some code that could help to accomplish this. It can be found in the HelperClass folder in the API layer.
Expected behavior An possible solution could be to check if the user exists in the database. Update the user if it's any different than in the seed.
Additional context The current logic to execute the seed in the startup
{
// seed roles
context.AddRange(Seed.SeedRoles());
context.SaveChanges();
}
List<Role> roles = context.Role.ToList();
if(!context.User.Any())
{
// seed admin
context.User.Add(Seed.SeedAdminUser(roles));
context.SaveChanges();
}