To use external services (like a Mailer or custom service) inside a migration, you must enable enable_service_migrations in your configuration. If you are not using default autoconfiguration, you must manually tag your migration classes with doctrine_migrations.migration in config/services.yaml.
# config/packages/doctrine_migrations.yaml
doctrine_migrations:
enable_service_migrations: true
migrations_paths:
'App\Migrations': '%kernel.project_dir%/src/Migrations'
# config/services.yaml
services:
DoctrineMigrations\Version20180605025653:
tags: [ 'doctrine_migrations.migration' ]
arguments:
$myService: '@App\Services\MyService'
// In your migration class
final class Version20180605025653 extends AbstractMigration
{
private MyService $myService;
public function __construct(Connection $connection, LoggerInterface $logger, MyService $myService)
{
parent::__construct($connection, $logger);
$this->myService = $myService;
}
// ...
}