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.url and wallabag_entry.given_url and wallabag_entry.user_id.
13 class Version20171218135243
extends AbstractMigration
implements ContainerAwareInterface
16 * @var ContainerInterface
20 private $indexGivenUrl = 'IDX_entry_given_url';
22 public function setContainer(ContainerInterface
$container = null)
24 $this->container
= $container;
28 * @param Schema $schema
30 public function up(Schema
$schema)
32 $entryTable = $schema->getTable($this->getTable('entry'));
33 $this->skipIf($entryTable->hasIndex($this->indexGivenUrl
), 'It seems that you already played this migration.');
35 switch ($this->connection
->getDatabasePlatform()->getName()) {
37 $sql = 'CREATE INDEX ' . $this->indexGivenUrl
. ' ON ' . $this->getTable('entry') . ' (url (255), given_url (255), user_id);';
40 $sql = 'CREATE INDEX ' . $this->indexGivenUrl
. ' ON ' . $this->getTable('entry') . ' (url, given_url, user_id);';
48 * @param Schema $schema
50 public function down(Schema
$schema)
52 $entryTable = $schema->getTable($this->getTable('entry'));
53 $this->skipIf(false === $entryTable->hasIndex($this->indexGivenUrl
), 'It seems that you already played this migration.');
55 $entryTable->dropIndex($this->indexGivenUrl
);
58 private function getTable($tableName)
60 return $this->container
->getParameter('database_table_prefix') . $tableName;