3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\AbstractMigration
;
6 use Doctrine\DBAL\Schema\Schema
;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface
;
8 use Symfony\Component\DependencyInjection\ContainerInterface
;
9 use Wallabag\CoreBundle\Entity\Entry
;
11 class Version20160410190541
extends AbstractMigration
implements ContainerAwareInterface
14 * @var ContainerInterface
18 public function setContainer(ContainerInterface
$container = null)
20 $this->container
= $container;
24 * @param Schema $schema
26 public function up(Schema
$schema)
28 $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL');
31 public function postUp(Schema
$schema)
33 $em = $this->container
->get('doctrine.orm.entity_manager');
34 $repository = $em->getRepository('WallabagCoreBundle:Entry');
35 $entries = $repository->findAll();
37 /** @var Entry $entry */
38 foreach ($entries as $entry) {
39 $this->addSql('UPDATE `wallabag_entry` SET `uuid` = "'.uniqid('', true).'" WHERE id = '.$entry->getId());
44 * @param Schema $schema
46 public function down(Schema
$schema)
48 $this->abortIf($this->connection
->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.');
49 $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`');