]>
Commit | Line | Data |
---|---|---|
d0545b6b NL |
1 | <?php |
2 | ||
3 | namespace Application\Migrations; | |
4 | ||
5 | use Doctrine\DBAL\Migrations\AbstractMigration; | |
6 | use Doctrine\DBAL\Schema\Schema; | |
a7e2218e NL |
7 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
8 | use Symfony\Component\DependencyInjection\ContainerInterface; | |
9 | use Wallabag\CoreBundle\Entity\Entry; | |
d0545b6b | 10 | |
a7e2218e | 11 | class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface |
d0545b6b | 12 | { |
a7e2218e NL |
13 | /** |
14 | * @var ContainerInterface | |
15 | */ | |
16 | private $container; | |
17 | ||
18 | public function setContainer(ContainerInterface $container = null) | |
19 | { | |
20 | $this->container = $container; | |
21 | } | |
22 | ||
d0545b6b NL |
23 | /** |
24 | * @param Schema $schema | |
25 | */ | |
26 | public function up(Schema $schema) | |
27 | { | |
a7e2218e | 28 | $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); |
9a5231e8 | 29 | } |
a7e2218e | 30 | |
9a5231e8 NL |
31 | public function postUp(Schema $schema) |
32 | { | |
a7e2218e | 33 | $em = $this->container->get('doctrine.orm.entity_manager'); |
9a5231e8 NL |
34 | $repository = $em->getRepository('WallabagCoreBundle:Entry'); |
35 | $entries = $repository->findAll(); | |
a7e2218e NL |
36 | |
37 | /** @var Entry $entry */ | |
38 | foreach ($entries as $entry) { | |
9a5231e8 | 39 | $this->addSql('UPDATE `wallabag_entry` SET `uuid` = "'.uniqid('', true).'" WHERE id = '.$entry->getId()); |
a7e2218e | 40 | } |
d0545b6b NL |
41 | } |
42 | ||
43 | /** | |
44 | * @param Schema $schema | |
45 | */ | |
46 | public function down(Schema $schema) | |
47 | { | |
9a5231e8 | 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.'); |
a7e2218e | 49 | $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); |
d0545b6b NL |
50 | } |
51 | } |