Do you want to know how to Drupal?

Let's Drupal

How to run a migration programmatically in Drupal 9?

The code bellow display how to execute the migration not through the command line, but through the code

First we need to load Migration. You can create it from a plugin, in this case the migration file is stored in migrations folder

 

use Drupal\migrate\MigrateMessage;
use Drupal\migrate_plus\Entity\Migration;
use Drupal\migrate_tools\MigrateExecutable;


// Load migration plugin.
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);

or load it it from config entity

// Load migration from config entity.

$migration = \Drupal\migrate_plus\Entity\Migration::load($migration_id);

And then run the import

$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import().