How to customise Identity user model in CMS 12?

Vote:
 

We're looking to extend the user model (ApplicationUser) with an extra field. Following the CMS docs here (https://world.optimizely.com/documentation/developer-guides/CMS/security/episerver-aspnetidentity/), we have this setup:

public class CustomUser : ApplicationUser { public string CustomData { get; set; } }

// In Startup.cs:
services.AddCmsAspNetIdentity<CustomUser>();

With this, however, during application start, we encounter the error "SqlException, invalid column name 'CustomData' ". Upon investigation, this is because in the database, the table dbo.AspNetUsers does not have the column CustomData created.

Going through the internet researching this, it seems like there is consensus that the documentation failed to detail the migration step: updating the database to reflect this new change:

With this in mind, when we go into the database and manually add the column to the AspNetUsers table, the error goes away as expected. But Optimizely obviously does not recommend interfering with the database schema, and our implementation will eventually be hosted on DXP.

We have opened a support ticket (#893747), and Optimizely is currently processing it, but we wanted to try and see if others on the forums have solved this issue before, and what's the best practice recommendation to solving this issue.

#278989
Apr 22, 2022 6:48
Vote:
 

There's some migration information in the new document system https://docs.developers.optimizely.com/content-cloud/v12.0.0-content-cloud/docs/aspnetidentity that's replaced the world docs.

#278999
Apr 22, 2022 9:19
btranorchard - Apr 25, 2022 23:36
Hey there, thanks for the reply. I've tried the line in the docs page, but it looks like there isn't a configureSqlServerOptions argument in the AddCmsIdentity method. There is only configureIdentity and configureIdentityBuilder, and neither of them has the MigrationsAssembly option. I have the UI.AspNetIdentity package installed.
Vote:
 

A new version of episerver-identity is in testing that will automigrate the schema for you.  For now you can see the script here here

#279077
Apr 23, 2022 16:18
btranorchard - Apr 25, 2022 23:40
Hey there, thanks for the reply. During testing we certainly can run SQL scripts against the test instance, but eventually we will be hosting the site on DXP for production, and we're concerned about damaging the warranty agreement if we touch the database schema there. Will this script be safe for that use?
Vote:
 

We have decided instead to switch to using ApplicationUserManager and a claims-based approach to storing user information, since extending the user model at this time involves too much custom and risky database work.

#279228
Apr 26, 2022 7:15
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.