]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/DoctrineMigrations/Version20171218135243.php
7b3fc6669f8ab19d8f0b3bbd8371e073d6da5b9e
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20171218135243.php
1 <?php
2
3 namespace Application\Migrations;
4
5 use Doctrine\DBAL\Migrations\AbstractMigration;
6 use Doctrine\DBAL\Schema\Schema;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11 * Added indexes on wallabag_entry.url and wallabag_entry.given_url and wallabag_entry.user_id.
12 */
13 class 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 }