From d0545b6bd6edc38bf06604900b1e20a60e7c8583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 10 Apr 2016 21:48:11 +0200 Subject: Add migration --- app/DoctrineMigrations/Version20160410190541.php | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/DoctrineMigrations/Version20160410190541.php (limited to 'app/DoctrineMigrations/Version20160410190541.php') diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php new file mode 100644 index 00000000..b30a898c --- /dev/null +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE wallabag_entry ADD uuid LONGTEXT DEFAULT NULL'); + $this->addSql('UPDATE wallabag_entry SET uuid = uuid()'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $this->addSql('ALTER TABLE `wallabag_entry` DROP uuid'); + } +} -- cgit v1.2.3 From a7e2218e253138ed53e18b4775dce291c78246c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 15 Apr 2016 13:42:13 +0200 Subject: Add test and fix migration --- app/DoctrineMigrations/Version20160410190541.php | 35 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'app/DoctrineMigrations/Version20160410190541.php') 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; use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Wallabag\CoreBundle\Entity\Entry; -class Version20160410190541 extends AbstractMigration +class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface { + /** + * @var ContainerInterface + */ + private $container; + + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } + /** * @param Schema $schema */ public function up(Schema $schema) { - $this->addSql('ALTER TABLE wallabag_entry ADD uuid LONGTEXT DEFAULT NULL'); - $this->addSql('UPDATE wallabag_entry SET uuid = uuid()'); + $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); + + $em = $this->container->get('doctrine.orm.entity_manager'); + $queryBuilder = $this->connection->createQueryBuilder(); + $queryBuilder + ->select('e.uuid') + ->andWhere('e.uuid IS NULL'); + $entries = $queryBuilder->execute(); + + /** @var Entry $entry */ + foreach ($entries as $entry) { + $entry->generateUuid(); + $em->persist($entry); + $em->clear(); + } + $em->flush(); } /** @@ -21,6 +48,6 @@ class Version20160410190541 extends AbstractMigration */ public function down(Schema $schema) { - $this->addSql('ALTER TABLE `wallabag_entry` DROP uuid'); + $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); } } -- cgit v1.2.3 From 9a5231e8c424bf92c164c9bd27a9660c17cc7852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 18 Apr 2016 22:45:52 +0200 Subject: Improve migration --- app/DoctrineMigrations/Version20160410190541.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'app/DoctrineMigrations/Version20160410190541.php') 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 public function up(Schema $schema) { $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); + } + public function postUp(Schema $schema) + { $em = $this->container->get('doctrine.orm.entity_manager'); - $queryBuilder = $this->connection->createQueryBuilder(); - $queryBuilder - ->select('e.uuid') - ->andWhere('e.uuid IS NULL'); - $entries = $queryBuilder->execute(); + $repository = $em->getRepository('WallabagCoreBundle:Entry'); + $entries = $repository->findAll(); /** @var Entry $entry */ foreach ($entries as $entry) { - $entry->generateUuid(); - $em->persist($entry); - $em->clear(); + $this->addSql('UPDATE `wallabag_entry` SET `uuid` = "'.uniqid('', true).'" WHERE id = '.$entry->getId()); } - $em->flush(); } /** @@ -48,6 +45,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI */ public function down(Schema $schema) { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); } } -- cgit v1.2.3 From f1be7af446052c6fed7033664c6c6350f558961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 23 Aug 2016 16:49:12 +0200 Subject: Change share entry behavior --- app/DoctrineMigrations/Version20160410190541.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'app/DoctrineMigrations/Version20160410190541.php') diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index f35f54ce..77c78c54 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -28,18 +28,6 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); } - public function postUp(Schema $schema) - { - $em = $this->container->get('doctrine.orm.entity_manager'); - $repository = $em->getRepository('WallabagCoreBundle:Entry'); - $entries = $repository->findAll(); - - /** @var Entry $entry */ - foreach ($entries as $entry) { - $this->addSql('UPDATE `wallabag_entry` SET `uuid` = "'.uniqid('', true).'" WHERE id = '.$entry->getId()); - } - } - /** * @param Schema $schema */ -- cgit v1.2.3 From ad9304cd7ed139dc59d6f40e6f8f4adcc6923c80 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Aug 2016 21:38:26 +0200 Subject: Handle table prefix in migration and fix migration for name field in oauth table --- app/DoctrineMigrations/Version20160410190541.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'app/DoctrineMigrations/Version20160410190541.php') diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index 77c78c54..5030d9c2 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Wallabag\CoreBundle\Entity\Entry; class Version20160410190541 extends AbstractMigration implements ContainerAwareInterface { @@ -20,12 +19,17 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI $this->container = $container; } + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix') . $tableName; + } + /** * @param Schema $schema */ public function up(Schema $schema) { - $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); + $this->addSql('ALTER TABLE `'.$this->getTable('entry').'` ADD `uuid` LONGTEXT DEFAULT NULL'); } /** @@ -34,6 +38,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI public function down(Schema $schema) { $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); - $this->addSql('ALTER TABLE `wallabag_entry` DROP `uuid`'); + + $this->addSql('ALTER TABLE `'.$this->getTable('entry').'` DROP `uuid`'); } } -- cgit v1.2.3 From b1afef30dc5527e5bf57c3eff60b05ee478a6014 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Aug 2016 21:56:02 +0200 Subject: Handle share_entry - share_entry needs to be in the migration too - and it needs a translation --- app/DoctrineMigrations/Version20160410190541.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/DoctrineMigrations/Version20160410190541.php') diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index 5030d9c2..4014857b 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -30,6 +30,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI public function up(Schema $schema) { $this->addSql('ALTER TABLE `'.$this->getTable('entry').'` ADD `uuid` LONGTEXT DEFAULT NULL'); + $this->addSql("INSERT INTO `".$this->getTable('craue_config_setting')."` (`name`, `value`, `section`) VALUES ('share_public', '1', 'entry')"); } /** @@ -40,5 +41,6 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); $this->addSql('ALTER TABLE `'.$this->getTable('entry').'` DROP `uuid`'); + $this->addSql("DELETE FROM `".$this->getTable('craue_config_setting')."` WHERE `name` = 'share_public'"); } } -- cgit v1.2.3 From 4c79c51f998fbec0caba3cf20291a9a54916af09 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 9 Oct 2016 21:35:04 +0200 Subject: Fix PostgreSQL migrations --- app/DoctrineMigrations/Version20160410190541.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app/DoctrineMigrations/Version20160410190541.php') diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index 4014857b..f034b0e4 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -29,8 +29,13 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI */ public function up(Schema $schema) { - $this->addSql('ALTER TABLE `'.$this->getTable('entry').'` ADD `uuid` LONGTEXT DEFAULT NULL'); - $this->addSql("INSERT INTO `".$this->getTable('craue_config_setting')."` (`name`, `value`, `section`) VALUES ('share_public', '1', 'entry')"); + if ($this->connection->getDatabasePlatform()->getName() == 'postgresql') { + $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid UUID DEFAULT NULL'); + } else { + $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid LONGTEXT DEFAULT NULL'); + } + + $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('share_public', '1', 'entry')"); } /** @@ -40,7 +45,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI { $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); - $this->addSql('ALTER TABLE `'.$this->getTable('entry').'` DROP `uuid`'); - $this->addSql("DELETE FROM `".$this->getTable('craue_config_setting')."` WHERE `name` = 'share_public'"); + $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" DROP uuid'); + $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'share_public'"); } } -- cgit v1.2.3