@@ -229,6 +229,67 @@ You can skip single migrations by explicitly adding them to the ``migration_vers
229
229
230
230
Doctrine will then assume that this migration has already been run and will ignore it.
231
231
232
+ Migration Dependencies
233
+ ----------------------
234
+
235
+ Migrations can have dependencies on external services (such as geolocation, mailer, data processing services...) that
236
+ can be used to have more powerful migrations. Those dependencies are not automatically injected into your migrations
237
+ but need to be injected using custom migrations factories.
238
+
239
+ Here is an example on how to inject the service container into your migrations:
240
+
241
+ .. configuration-block ::
242
+
243
+ .. code-block :: yaml
244
+
245
+ # config/packages/doctrine_migrations.yml
246
+ doctrine_migrations :
247
+ services :
248
+ ' Doctrine\Migrations\Version\MigrationFactory ' : ' App\Migrations\Factory\MigrationFactoryDecorator'
249
+
250
+ # config/services.yml
251
+ services :
252
+ Doctrine\Migrations\Version\DbalMigrationFactory : ~
253
+ App\Migrations\Factory\MigrationFactoryDecorator :
254
+ decorates : Doctrine\Migrations\Version\DbalMigrationFactory
255
+ arguments : ['@App\Migrations\Factory\MigrationFactoryDecorator.inner', '@service_container']
256
+
257
+
258
+ .. code-block :: php
259
+
260
+ declare(strict_types=1);
261
+
262
+ namespace App\Migrations\Factory;
263
+
264
+ use Doctrine\Migrations\AbstractMigration;
265
+ use Doctrine\Migrations\Version\MigrationFactory;
266
+ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
267
+ use Symfony\Component\DependencyInjection\ContainerInterface;
268
+
269
+ class MigrationFactoryDecorator implements MigrationFactory
270
+ {
271
+ private $migrationFactory;
272
+ private $container;
273
+
274
+ public function __construct(MigrationFactory $migrationFactory, ContainerInterface $container)
275
+ {
276
+ $this->migrationFactory = $migrationFactory;
277
+ $this->container = $container;
278
+ }
279
+
280
+ public function createVersion(string $migrationClassName): AbstractMigration
281
+ {
282
+ $instance = $this->migrationFactory->createVersion($migrationClassName);
283
+
284
+ if ($instance instanceof ContainerAwareInterface) {
285
+ $instance->setContainer($this->container);
286
+ }
287
+
288
+ return $instance;
289
+ }
290
+ }
291
+
292
+
232
293
Generating Migrations Automatically
233
294
-----------------------------------
234
295
0 commit comments