Hey all,
After this change https://github.com/aspnetzero/aspnet-zero-core/pull/5828/changes
Can you provide some guidance on the data migration that is required to make the user account links work again. This is a big key feature of our existing system using the AbpUserAccounts table.
Is there some guidance on what the expected data migration to this new table should be? A migration DB script would be great too :)
Thanks
2 Answer(s)
-
0
Hi @rickfrankel
Thanks for raising this. Here’s the data migration guidance to move from the old
UserLinkIdbased grouping onAbpUserAccountsto the new explicitUserAccountLinksjunction table so account linking works again.What changed
- Old model: Linked users shared the same
UserLinkIdvalue inAbpUserAccounts. Typically the “root” account hadUserLinkId = Id, and all linked accounts pointed to that sameUserLinkId(or otherwise shared the same group value). - New model: Links are stored as explicit rows in a junction table:
UserAccountLinks(UserAccountId, LinkedUserAccountId, CreationTime, ...).
Expected migration behavior
For each link group (all
AbpUserAccountsrows with the same non nullUserLinkId), you should create link rows between every account in that group. The application previously treated the group as fully linked, so we need to preserve that semantics.Run after applying the migration that creates
UserAccountLinks(e.g.,Add_User_Account_Link_Entity)./* Migrate existing linked accounts from UserLinkId groups to UserAccountLinks. This generates directed links A->B and B->A for each group, matching the prior linked group semantics. Safe to re run due to NOT EXISTS. */ INSERT INTO UserAccountLinks (UserAccountId, LinkedUserAccountId, CreationTime) SELECT ua1.Id AS UserAccountId, ua2.Id AS LinkedUserAccountId, GETUTCDATE() AS CreationTime FROM AbpUserAccounts ua1 JOIN AbpUserAccounts ua2 ON ua1.UserLinkId = ua2.UserLinkId WHERE ua1.UserLinkId IS NOT NULL AND ua1.Id <> ua2.Id AND NOT EXISTS ( SELECT 1 FROM UserAccountLinks ual WHERE ual.UserAccountId = ua1.Id AND ual.LinkedUserAccountId = ua2.Id );- If your
UserAccountLinkstable uses theAbpUserAccountLinksnaming (or has extra required columns likeTenantId), you’ll need to adjust the table/column list accordingly. - The
UserLinkIdcolumn may still exist inAbpUserAccountsafter the change but it’s no longer used by the app logic.
If you encounter any issues while applying this migration, please don’t hesitate to reach out to us.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) - Old model: Linked users shared the same
-
0
Thanks that works well. Much appreciated.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)