aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-04-15 13:42:13 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-08-23 16:49:21 +0200
commita7e2218e253138ed53e18b4775dce291c78246c5 (patch)
treeb42d5a26987149f8372c49ef7f78a63ed81867e3 /app/DoctrineMigrations
parent222e09f140099f3b1b8f6db1846d35e6810d43a3 (diff)
downloadwallabag-a7e2218e253138ed53e18b4775dce291c78246c5.tar.gz
wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.tar.zst
wallabag-a7e2218e253138ed53e18b4775dce291c78246c5.zip
Add test and fix migration
Diffstat (limited to 'app/DoctrineMigrations')
-rw-r--r--app/DoctrineMigrations/Version20160410190541.php35
1 files changed, 31 insertions, 4 deletions
diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php
index b30a898c..775dd680 100644
--- a/app/DoctrineMigrations/Version20160410190541.php
+++ b/app/DoctrineMigrations/Version20160410190541.php
@@ -4,16 +4,43 @@ namespace Application\Migrations;
4 4
5use Doctrine\DBAL\Migrations\AbstractMigration; 5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema; 6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9use Wallabag\CoreBundle\Entity\Entry;
7 10
8class Version20160410190541 extends AbstractMigration 11class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface
9{ 12{
10 /** 13 /**
14 * @var ContainerInterface
15 */
16 private $container;
17
18 public function setContainer(ContainerInterface $container = null)
19 {
20 $this->container = $container;
21 }
22
23 /**
11 * @param Schema $schema 24 * @param Schema $schema
12 */ 25 */
13 public function up(Schema $schema) 26 public function up(Schema $schema)
14 { 27 {
15 $this->addSql('ALTER TABLE wallabag_entry ADD uuid LONGTEXT DEFAULT NULL'); 28 $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL');
16 $this->addSql('UPDATE wallabag_entry SET uuid = uuid()'); 29
30 $em = $this->container->get('doctrine.orm.entity_manager');
31 $queryBuilder = $this->connection->createQueryBuilder();
32 $queryBuilder
33 ->select('e.uuid')
34 ->andWhere('e.uuid IS NULL');
35 $entries = $queryBuilder->execute();
36
37 /** @var Entry $entry */
38 foreach ($entries as $entry) {
39 $entry->generateUuid();
40 $em->persist($entry);
41 $em->clear();
42 }
43 $em->flush();
17 } 44 }
18 45
19 /** 46 /**
@@ -21,6 +48,6 @@ class Version20160410190541 extends AbstractMigration
21 */ 48 */
22 public function down(Schema $schema) 49 public function down(Schema $schema)
23 { 50 {
24 $this->addSql('ALTER TABLE `wallabag_entry` DROP uuid'); 51 $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`');
25 } 52 }
26} 53}