Base solution for your next web application
Open Closed

Data migration guidance after this change https://github.com/aspnetzero/aspnet-zero-core/pull/5828/changes #12628


User avatar
0
rickfrankel created

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

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

2 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @rickfrankel

    Thanks for raising this. Here’s the data migration guidance to move from the old UserLinkIdbased grouping on AbpUserAccounts to the new explicit UserAccountLinks junction table so account linking works again.

    What changed

    • Old model: Linked users shared the same UserLinkId value in AbpUserAccounts. Typically the “root” account had UserLinkId = Id, and all linked accounts pointed to that same UserLinkId (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 AbpUserAccounts rows with the same non null UserLinkId), 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 UserAccountLinks table uses the AbpUserAccountLinks naming (or has extra required columns like TenantId), you’ll need to adjust the table/column list accordingly.
    • The UserLinkId column may still exist in AbpUserAccounts after 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 supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    rickfrankel created

    Thanks that works well. Much appreciated.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)