So I\'ve done a bunch of Doctrine2 migrations (https://github.com/doctrine/migrations) but I have a question for a new migration I\'m trying to do.
I\'ve been digging in
FYI, latest docs show this example that is even better with a "postUp" method
http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
// ...
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)
{
$em = $this->container->get('doctrine.orm.entity_manager');
// ... update the entities
}
}
You can use the $connection
like this
$result = $this->connection->fetchAssoc('SELECT id, name FROM table1 WHERE id = 1');
$this->abortIf(!$result, 'row with id not found');
$this->abortIf($result['name'] != 'jo', 'id 1 is not jo');
// etc..
You should only read the database and not use the connection to make update/delete so it won't break the dry-run option.
In your example, you should do two migrations. The first will do the two alter table. The second will do the "images with a scrape and convert the scrape to an enclosure" routine. Using multiple migration is easier to revert them if something goes wrong.