Update Asset Index in Migration I'm trying to index some asset volumes that I'm creating in a migration. These are local volumes which may already contain files. 

I'm hoping to avoid the step where I have to manually update the asset indices after creating volumes.

The following code does not seem to perform the index, am I missing a step? I've studied the controller used by Utilities but I can't see where I'm going wrong.

    $volumeId = Craft::$app-&gt;volumes-&gt;getVolumeByHandle('myVolume')-&gt;id;

    $indexer = Craft::$app-&gt;getAssetIndexer();

    $sessionId = $indexer-&gt;getIndexingSessionid();

    $indexer-&gt;processIndexForVolume($sessionId,$volumeId);


Any help is much appreciated
As of 3.1.2 you can now index assets via the cli tool:

./craft index-assets/all 


OR

./craft index-assets/one {handle}