diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-18 22:45:52 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-08-23 16:49:21 +0200 |
commit | 9a5231e8c424bf92c164c9bd27a9660c17cc7852 (patch) | |
tree | 67ee6d9decb1ed8990dcbef9f2048e55a50961af /app | |
parent | a7e2218e253138ed53e18b4775dce291c78246c5 (diff) | |
download | wallabag-9a5231e8c424bf92c164c9bd27a9660c17cc7852.tar.gz wallabag-9a5231e8c424bf92c164c9bd27a9660c17cc7852.tar.zst wallabag-9a5231e8c424bf92c164c9bd27a9660c17cc7852.zip |
Improve migration
Diffstat (limited to 'app')
-rw-r--r-- | app/DoctrineMigrations/Version20160410190541.php | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index 775dd680..f35f54ce 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php | |||
@@ -26,21 +26,18 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI | |||
26 | public function up(Schema $schema) | 26 | public function up(Schema $schema) |
27 | { | 27 | { |
28 | $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); | 28 | $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); |
29 | } | ||
29 | 30 | ||
31 | public function postUp(Schema $schema) | ||
32 | { | ||
30 | $em = $this->container->get('doctrine.orm.entity_manager'); | 33 | $em = $this->container->get('doctrine.orm.entity_manager'); |
31 | $queryBuilder = $this->connection->createQueryBuilder(); | 34 | $repository = $em->getRepository('WallabagCoreBundle:Entry'); |
32 | $queryBuilder | 35 | $entries = $repository->findAll(); |
33 | ->select('e.uuid') | ||
34 | ->andWhere('e.uuid IS NULL'); | ||
35 | $entries = $queryBuilder->execute(); | ||
36 | 36 | ||
37 | /** @var Entry $entry */ | 37 | /** @var Entry $entry */ |
38 | foreach ($entries as $entry) { | 38 | foreach ($entries as $entry) { |
39 | $entry->generateUuid(); | 39 | $this->addSql('UPDATE `wallabag_entry` SET `uuid` = "'.uniqid('', true).'" WHERE id = '.$entry->getId()); |
40 | $em->persist($entry); | ||
41 | $em->clear(); | ||
42 | } | 40 | } |
43 | $em->flush(); | ||
44 | } | 41 | } |
45 | 42 | ||
46 | /** | 43 | /** |
@@ -48,6 +45,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI | |||
48 | */ | 45 | */ |
49 | public function down(Schema $schema) | 46 | public function down(Schema $schema) |
50 | { | 47 | { |
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.'); | ||
51 | $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); | 49 | $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); |
52 | } | 50 | } |
53 | } | 51 | } |