]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20171218135243.php
Removed SQLite migration
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20171218135243.php
CommitLineData
024e9abf
NL
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()) {
024e9abf
NL
36 case 'mysql':
37 $sql = 'CREATE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url (255), given_url (255), user_id);';
38 break;
39 case 'postgresql':
40 $sql = 'CREATE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url, given_url, user_id);';
41 break;
42 }
43
44 $this->addSql($sql);
45 }
46
47 /**
48 * @param Schema $schema
49 */
50 public function down(Schema $schema)
51 {
52 $entryTable = $schema->getTable($this->getTable('entry'));
53 $this->skipIf(false === $entryTable->hasIndex($this->indexGivenUrl), 'It seems that you already played this migration.');
54
55 $entryTable->dropIndex($this->indexGivenUrl);
56 }
57
58 private function getTable($tableName)
59 {
60 return $this->container->getParameter('database_table_prefix') . $tableName;
61 }
62}