# Package Migration Plans - Do they support async at all?

**URL:** <https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316>\
**Category:** Questions\
**Tags:** v15, packages\
**Created:** [February 27, 2025, 3:28pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316 "2025-02-27T15:28:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [February 27, 2025, 3:28pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316/1 "2025-02-27T15:28:43Z")

</div>

Hello,  
I am working on a package migration which runs when the package is installed.

With a lot of the newer bits and pieces of Umbraco supporting Async methods in the services. I was wondering if PackageMigrations support async at all?

As writing `.Result` in my code is giving me the heebie jeebies

```csharp
// Booo :( the Migrate from PackageMigrationBase does not support Async it seems ?!
var adminGroup = _userGroupService.GetAsync(Umbraco.Cms.Core.Constants.Security.AdminGroupKey).Result;

```

![Squirm](https://forum.umbraco.com/uploads/default/original/1X/2b9ed3f6f39ab61a4e2335a1c0eb8b34cdd415f3.gif)

## Example Code

This is what I have and was hoping to not use .Result in the codebase.

```csharp
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Infrastructure.Migrations;
using Umbraco.Cms.Infrastructure.Packaging;

namespace ContentLock.Migrations.v1
{
    public class AddUserPermissionToAdmins : PackageMigrationBase
    {
        private readonly IUserGroupService _userGroupService;
        private readonly ILogger<AddUserPermissionToAdmins> _logger;

        public AddUserPermissionToAdmins(IPackagingService packagingService,
            IMediaService mediaService,
            MediaFileManager mediaFileManager,
            MediaUrlGeneratorCollection mediaUrlGenerators,
            IShortStringHelper shortStringHelper,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
            IMigrationContext context,
            IOptions<PackageMigrationSettings> packageMigrationsSettings,
            IUserGroupService userGroupService,
            IUserService userService,
            ILogger<AddUserPermissionToAdmins> logger)
            : base(
                  packagingService,
                  mediaService,
                  mediaFileManager,
                  mediaUrlGenerators,
                  shortStringHelper,
                  contentTypeBaseServiceProvider,
                  context,
                  packageMigrationsSettings)
        {
            _userGroupService = userGroupService;
            _logger = logger;
        }

        protected override void Migrate()
        {
            // Booo :( the Migrate from PackageMigrationBase does not support Async
            var adminGroup = _userGroupService.GetAsync(Umbraco.Cms.Core.Constants.Security.AdminGroupKey).Result;

            if (adminGroup == null)
            {
                _logger.LogWarning("ContentLock is unable to find the default Umbraco Admin User Group. Exiting");
                return;
            }

            // Permissions ?!
            var permissions = adminGroup.Permissions;

            // Add new permission (Same as the permission verb in clientside code)
            permissions.Add("ContentLock.Enabled");

            // Update the user group
            var attempt = _userGroupService.UpdateAsync(adminGroup, Umbraco.Cms.Core.Constants.Security.SuperUserKey).Result;

            _logger.LogTrace("Updated default Umbraco Admin User Group with the 'ContentLock.Enabled' permission with this attempt status {status}", attempt.Status);

            if (!attempt.Success)
            {
                _logger.LogWarning("ContentLock was unable to update the default Umbraco Admin User Group with permission 'ContentLock.Enabled'");
                _logger.LogError(attempt.Exception, "Error updating the User Group permission");
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![KevinJump](https://forum.umbraco.com/user_avatar/forum.umbraco.com/kevinjump/32/186_2.png) [@KevinJump](https://forum.umbraco.com/u/KevinJump)\
**Post date:** [February 27, 2025, 3:45pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316/2 "2025-02-27T15:45:56Z")

</div>

I don’t think they are,

I was just looking at some ‘old-school’ migration stuff using MigrationPlans, and that isn’t async either , I think the whole migration pipeline is synchronous. ☹

---

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [February 27, 2025, 3:48pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316/3 "2025-02-27T15:48:43Z")

</div>

Current mood 👇

![](https://forum.umbraco.com/uploads/default/original/1X/4ba0f27949f27c2f57a22f42d6669d26108607d0.gif)  
OK for now I will pretend I didn’t see the .Result in that bit of the code and just move on.

Are you aware of any GitHub issues related to this at all ?

---

<div class="post-metadata">

**Author:** ![sebastiaan](https://forum.umbraco.com/user_avatar/forum.umbraco.com/sebastiaan/32/279_2.png) [@sebastiaan](https://forum.umbraco.com/u/sebastiaan)\
**Post date:** [February 27, 2025, 3:53pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316/4 "2025-02-27T15:53:13Z")

</div>

I’ve seen talks about “async all the things” at HQ but it’s a huge undertaking, definitely not there yet. [GitHub Discussions](https://github.com/umbraco/Umbraco-CMS/discussions) is good for feature requests!

---

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [February 27, 2025, 3:56pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316/5 "2025-02-27T15:56:47Z")

</div>

OK I clearly don’t ever remember creating this, but it seems I have already done so…

> **[V15: Support Async for PackageMigrationPlans · umbraco/Umbraco-CMS ·...](https://github.com/umbraco/Umbraco-CMS/discussions/17668)**
>
> Which Umbraco version are you using? (Please write the exact version, example: 10.1.0) 15.0.0 Bug summary As most of the Services & APIs in Umbraco are starting to go async it would be good to have...

Will close this now & suggest anyone reading/following along go there instead & vote it up or chime in please ☝

---

<div class="post-metadata">

**Author:** ![sebastiaan](https://forum.umbraco.com/user_avatar/forum.umbraco.com/sebastiaan/32/279_2.png) [@sebastiaan](https://forum.umbraco.com/u/sebastiaan)\
**Post date:** [February 27, 2025, 4:43pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316/6 "2025-02-27T16:43:49Z")

</div>

Ah, this is the related work I was remembering:

> <https://github.com/umbraco/Umbraco-CMS/pull/17057>
>
> \### Prerequisites
> 
> \- \[x\] I have added steps to test this contribution in the d…escription below
> 
> \### Description
> Similar to https://github.com/umbraco/Umbraco-CMS/pull/16536, this PR makes it possible to (correctly) call async methods in migrations. I've done the following:
> \- Added \`AsyncMigrationBase\` with new \`RunAsync()\` and \`MigrateAsync()\` methods, made this the base class of \`MigrationBase\` and moved most methods into this new class;
> \- Similarly,. added \`UnscopedAsyncMigrationBase\` and made this the base class of \`UnscopedMigrationBase\`, added \`AsyncPackageMigrationBase\` and made this the base class of \`PackageMigrationBase\`;
> \- Refactored \`IMigrationPlanExecutor\` to only have an \`ExecutePlanAsync()\` method;
> \- Updated all calls to use the new async methods.
> 
> Testing should be done by ensuring a clean install creates and updates the database correctly and checking whether the code and tests are all good 😄

---

<div class="post-metadata">

**Author:** ![system](https://forum.umbraco.com/uploads/default/original/1X/624adeddd330a3d0268a184db47946ca7e82c676.png) [@system](https://forum.umbraco.com/u/system)\
**Post date:** [March 4, 2025, 4:44pm UTC](https://forum.umbraco.com/t/package-migration-plans-do-they-support-async-at-all/316/7 "2025-03-04T16:44:46Z")

</div>

Closed on March 4, 2025, 4:44pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
