]>
Commit | Line | Data |
---|---|---|
1e7b04d4 JB |
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 | class Version20161104073720 extends AbstractMigration implements ContainerAwareInterface | |
11 | { | |
12 | /** | |
13 | * @var ContainerInterface | |
14 | */ | |
15 | private $container; | |
16 | ||
067ae472 NL |
17 | private $indexName = 'IDX_entry_created_at'; |
18 | ||
1e7b04d4 JB |
19 | public function setContainer(ContainerInterface $container = null) |
20 | { | |
21 | $this->container = $container; | |
22 | } | |
23 | ||
24 | private function getTable($tableName) | |
25 | { | |
a4d55a91 | 26 | return $this->container->getParameter('database_table_prefix').$tableName; |
1e7b04d4 JB |
27 | } |
28 | ||
29 | /** | |
30 | * @param Schema $schema | |
31 | */ | |
32 | public function up(Schema $schema) | |
33 | { | |
84c6a48d | 34 | $entryTable = $schema->getTable($this->getTable('entry')); |
067ae472 NL |
35 | $this->skipIf($entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.'); |
36 | ||
37 | $entryTable->addIndex(['created_at'], $this->indexName); | |
1e7b04d4 JB |
38 | } |
39 | ||
40 | /** | |
41 | * @param Schema $schema | |
42 | */ | |
43 | public function down(Schema $schema) | |
44 | { | |
067ae472 NL |
45 | $entryTable = $schema->getTable($this->getTable('entry')); |
46 | $this->skipIf(false === $entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.'); | |
47 | ||
48 | $entryTable->dropIndex($this->indexName); | |
1e7b04d4 JB |
49 | } |
50 | } |