]>
Commit | Line | Data |
---|---|---|
b564d350 NL |
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 | /** | |
01736b5a | 11 | * Added indexes on wallabag_entry.is_starred and wallabag_entry.is_archived. |
b564d350 NL |
12 | */ |
13 | class Version20170127093841 extends AbstractMigration implements ContainerAwareInterface | |
14 | { | |
15 | /** | |
16 | * @var ContainerInterface | |
17 | */ | |
18 | private $container; | |
19 | ||
20 | private $indexStarredName = 'IDX_entry_starred'; | |
21 | private $indexArchivedName = 'IDX_entry_archived'; | |
22 | ||
23 | public function setContainer(ContainerInterface $container = null) | |
24 | { | |
25 | $this->container = $container; | |
26 | } | |
27 | ||
28 | private function getTable($tableName) | |
29 | { | |
30 | return $this->container->getParameter('database_table_prefix').$tableName; | |
31 | } | |
32 | ||
33 | /** | |
34 | * @param Schema $schema | |
35 | */ | |
36 | public function up(Schema $schema) | |
37 | { | |
38 | $entryTable = $schema->getTable($this->getTable('entry')); | |
01e76069 | 39 | $this->skipIf($entryTable->hasIndex($this->indexStarredName) && $entryTable->hasIndex($this->indexArchivedName), 'It seems that you already played this migration.'); |
b564d350 NL |
40 | |
41 | $entryTable->addIndex(['is_starred'], $this->indexStarredName); | |
42 | $entryTable->addIndex(['is_archived'], $this->indexArchivedName); | |
43 | } | |
44 | ||
45 | /** | |
46 | * @param Schema $schema | |
47 | */ | |
48 | public function down(Schema $schema) | |
49 | { | |
50 | $entryTable = $schema->getTable($this->getTable('entry')); | |
01e76069 | 51 | $this->skipIf(false === $entryTable->hasIndex($this->indexStarredName) && false === $entryTable->hasIndex($this->indexArchivedName), 'It seems that you already played this migration.'); |
b564d350 NL |
52 | |
53 | $entryTable->dropIndex($this->indexStarredName); | |
54 | $entryTable->dropIndex($this->indexArchivedName); | |
55 | } | |
56 | } |