If it's a custom module you can use hook_deploy_NAME(&$sandbox)
inside MY_MODULE.deploy.php. drush deploy:hook
being executed as part of drush deploy
will pick up any hook_deploy_NAME
implementation even of just recently enabled modules.
So make sure you execute drush deploy
as part of your deployment routine, then your custom module will get enabled first from drush cim
(and an entry in the core.extension.yml of course) and your custom install logic will get run from drush deploy:hook
being executed after it.
Found out just recently that hook_deploy_NAME
implementations won't get registered on module enablement like hook_update_N
implementations are. Every existing hook_deploy_NAME
implementation will just be picked up.
Talked about it quickly with Moshe Weitzman (the Drush maintainer) on Drupal Slack asking if this is a bug and he said no it's a feature and that hook_deploy_NAME
implementations are supposed to only be used in custom modules.
See https://drupal.stackexchange.com/a/254411/15055 for all the commands that are part of drush deploy
.
Have you tried batch_set
in the install hook? https://drupal.stackexchange.com/a/310282/15055