Order of PackageMigrationPlans execution
# package-development
w
Package Champions: Question for you Do we know or can we control the order of PackageMigrationPlans ? As currently they are type scanned and we don't explicitly register them into the CollectionBuilder like other collections AFAIK So I have a package migration that depends on another package - how do I know that their package migration has run BEFORE mine?
How are they ordered for execution ? @Ronald Barendse any insights or perhaps the heavy weights such as @leekelleher or @Kevin Jump might have thoughts ??
Are they weighted like other collections or they ordered by Alpha or is there no gurantee of the order of excution?!
d
I'm just guessing here, but there's probably some collection builder that you can remove and reinsert it with. Could probably find it if you trace the references to package migration plan. The collection builder also determines whether or not it's ordered or weighted by the baseclass that the builder inherits from
w
Yeh I need to go source code diving...
r
Hi Warren! The package migrations are indeed type scanned here: https://github.com/umbraco/Umbraco-CMS/blob/0bbda02931e77e5750a66c84ffab870965d2ab30/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs#L80 And added to a lazy collection builder: https://github.com/umbraco/Umbraco-CMS/blob/0bbda02931e77e5750a66c84ffab870965d2ab30/src/Umbraco.Infrastructure/Packaging/PackageMigrationPlanCollectionBuilder.cs#L5 So that means they're not ordered 😢 Changing this to another type will be a breaking change, but it might make sense to either be able to manually order them (
OrderedCollectionBuilderBase
) or add weights (
WeightedCollectionBuilder
): https://docs.umbraco.com/umbraco-cms/implementation/composing#types-of-collections
w
Shall I raise an issue for this @Ronald Barendse to discuss what options should be
r
Can't you influence it by addding ComposeAfter attribute on the Composer that triggers the Migration?
k
you can for 'old school' migrations, because you run them but PackageMigrations are autodiscoved by type and ran in the core, you don't actually get to give an order.
I think the PackageMigration collection could be made a weighted collection and then you could add a weight to dictate the order, but that requires core changes.
at the moment i think the only way is to use an 'normal' migration and do as you say and use ComposeAfter
w
Err I wanted to use PackageMigrations and not old school ones - will raise a PR issue to discuss and see what HQ gang think
r
This would definitely be something we should discuss (and potentially fix in v13), because it makes sense for certain migrations to run before/after others... So feel free to create a new discussion on the issue tracker @Warren Buckley 👍 Deploy 12 is now also using a package migration to create its database tables, because other packages might use it to create content/schema and Deploy then handles the notifications to write the artifacts to disk and update signatures in the database. Previously we used a custom migration that was executed in a composer, later in the starting notification handler, but both were running after package migrations and therefore too late (ending up in database errors, because the tables don't exist yet on the first startup, which is also most likely when the package migrations are executed)...
w
One issue for you @Ronald Barendse & @Sebastiaan https://github.com/umbraco/Umbraco-CMS/issues/14813
Happy FriYay & weekend all
j
@Warren Buckley do you know if this got any traction, something we need to do also
r
Although the following PR is marked as closed, the changes are actually in v13: https://github.com/umbraco/Umbraco-CMS/pull/15138
And Deploy 13 uses weight -100, ensuring it's installed and handling schema/content updates before other package migrations are executed 👌
j
@Ronald Barendse legend - any idea on where to place this weight?
s
This should do the trick:
Copy code
csharp
[Weight(10)]
public class MyMigrationPlan : PackageMigrationPlan
25 Views