3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\AbstractMigration
;
6 use Doctrine\DBAL\Schema\Schema
;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface
;
8 use Symfony\Component\DependencyInjection\ContainerInterface
;
11 * Added indexes on wallabag_entry.is_starred and wallabag_entry.is_archived.
13 class Version20170127093841
extends AbstractMigration
implements ContainerAwareInterface
16 * @var ContainerInterface
20 private $indexStarredName = 'IDX_entry_starred';
21 private $indexArchivedName = 'IDX_entry_archived';
23 public function setContainer(ContainerInterface
$container = null)
25 $this->container
= $container;
29 * @param Schema $schema
31 public function up(Schema
$schema)
33 $entryTable = $schema->getTable($this->getTable('entry'));
34 $this->skipIf($entryTable->hasIndex($this->indexStarredName
) && $entryTable->hasIndex($this->indexArchivedName
), 'It seems that you already played this migration.');
36 $entryTable->addIndex(['is_starred'], $this->indexStarredName
);
37 $entryTable->addIndex(['is_archived'], $this->indexArchivedName
);
41 * @param Schema $schema
43 public function down(Schema
$schema)
45 $entryTable = $schema->getTable($this->getTable('entry'));
46 $this->skipIf(false === $entryTable->hasIndex($this->indexStarredName
) && false === $entryTable->hasIndex($this->indexArchivedName
), 'It seems that you already played this migration.');
48 $entryTable->dropIndex($this->indexStarredName
);
49 $entryTable->dropIndex($this->indexArchivedName
);
52 private function getTable($tableName)
54 return $this->container
->getParameter('database_table_prefix') . $tableName;