Skip to content

Commit

Permalink
Remove container aware migrations documentation
Browse files Browse the repository at this point in the history
It's not recommended to use services in migrations because they could change or be removed, which could leave your database in an unpredictable state.

See #243 for more information.
  • Loading branch information
j4nr6n committed Nov 19, 2018
1 parent c7373c2 commit a6ce2c2
Showing 1 changed file with 0 additions and 61 deletions.
61 changes: 0 additions & 61 deletions Resources/doc/index.rst
Expand Up @@ -329,67 +329,6 @@ If you don't want to use this workflow and instead create your schema via
Otherwise Doctrine will try to run all migrations, which probably will not work.
Container Aware Migrations
--------------------------
In some cases you might need access to the container to ensure the proper update of
your data structure. This could be necessary to update relations with some specific
logic or to create new entities.
Therefore you can just implement the ContainerAwareInterface with its needed methods
to get full access to the container or ContainerAwareTrait if you use Symfony >= 2.4.
.. code-block:: php
// ...
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Version20130326212938 extends AbstractMigration implements ContainerAwareInterface
{
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
public function up(Schema $schema)
{
// ... migration content
}
public function postUp(Schema $schema)
{
$converter = $this->container->get('my_service.convert_data_to');
// ... convert the data from markdown to html for instance
}
}
With the trait
.. code-block:: php
// ...
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
class Version20130326212938 extends AbstractMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function up(Schema $schema)
{
// ... migration content
}
public function postUp(Schema $schema)
{
$converter = $this->container->get('my_service.convert_data_to');
// ... convert the data from markdown to html for instance
}
}
Manual Tables
-------------
Expand Down

0 comments on commit a6ce2c2

Please sign in to comment.