aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-12-18 14:57:25 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2017-12-18 20:00:39 +0100
commit024e9abf38f4c72566ff37bc0c1a1d3637fe632e (patch)
tree58ecfda692044a0ea0bc719884b619d9c21405ea
parentdfa18939e87c4e8f8f61124f3fcf6ae3f36fc44c (diff)
downloadwallabag-024e9abf38f4c72566ff37bc0c1a1d3637fe632e.tar.gz
wallabag-024e9abf38f4c72566ff37bc0c1a1d3637fe632e.tar.zst
wallabag-024e9abf38f4c72566ff37bc0c1a1d3637fe632e.zip
Added index on entry table for given_url field
-rw-r--r--app/DoctrineMigrations/Version20171218135243.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20171218135243.php b/app/DoctrineMigrations/Version20171218135243.php
new file mode 100644
index 00000000..7b3fc666
--- /dev/null
+++ b/app/DoctrineMigrations/Version20171218135243.php
@@ -0,0 +1,65 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
10/**
11 * Added indexes on wallabag_entry.url and wallabag_entry.given_url and wallabag_entry.user_id.
12 */
13class Version20171218135243 extends AbstractMigration implements ContainerAwareInterface
14{
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 private $indexGivenUrl = 'IDX_entry_given_url';
21
22 public function setContainer(ContainerInterface $container = null)
23 {
24 $this->container = $container;
25 }
26
27 /**
28 * @param Schema $schema
29 */
30 public function up(Schema $schema)
31 {
32 $entryTable = $schema->getTable($this->getTable('entry'));
33 $this->skipIf($entryTable->hasIndex($this->indexGivenUrl), 'It seems that you already played this migration.');
34
35 switch ($this->connection->getDatabasePlatform()->getName()) {
36 case 'sqlite':
37 $sql = 'CREATE UNIQUE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url, given_url, user_id);';
38 break;
39 case 'mysql':
40 $sql = 'CREATE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url (255), given_url (255), user_id);';
41 break;
42 case 'postgresql':
43 $sql = 'CREATE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url, given_url, user_id);';
44 break;
45 }
46
47 $this->addSql($sql);
48 }
49
50 /**
51 * @param Schema $schema
52 */
53 public function down(Schema $schema)
54 {
55 $entryTable = $schema->getTable($this->getTable('entry'));
56 $this->skipIf(false === $entryTable->hasIndex($this->indexGivenUrl), 'It seems that you already played this migration.');
57
58 $entryTable->dropIndex($this->indexGivenUrl);
59 }
60
61 private function getTable($tableName)
62 {
63 return $this->container->getParameter('database_table_prefix') . $tableName;
64 }
65}