1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Surfnet\StepupMiddleware\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
|
|
|
/** |
11
|
|
|
* Update the Gateway `second_factor` table setting the primary key on the `id` and `identity_id` fields. |
12
|
|
|
*/ |
13
|
|
|
class Version20180131150800 extends AbstractMigration implements ContainerAwareInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var ContainerInterface |
17
|
|
|
*/ |
18
|
|
|
private $container; |
19
|
|
|
|
20
|
|
|
public function setContainer(ContainerInterface $container = null) |
21
|
|
|
{ |
22
|
|
|
$this->container = $container; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Schema $schema |
27
|
|
|
*/ |
28
|
|
|
public function up(Schema $schema) |
29
|
|
|
{ |
30
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
31
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
32
|
|
|
|
33
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
34
|
|
|
|
35
|
|
|
$this->addSql(sprintf('ALTER TABLE %s.second_factor DROP PRIMARY KEY', $gatewaySchema)); |
36
|
|
|
$this->addSql(sprintf('ALTER TABLE %s.second_factor ADD PRIMARY KEY (id, identity_id)', $gatewaySchema)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param Schema $schema |
41
|
|
|
*/ |
42
|
|
|
public function down(Schema $schema) |
43
|
|
|
{ |
44
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
45
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
46
|
|
|
|
47
|
|
|
$gatewaySchema = $this->getGatewaySchema(); |
48
|
|
|
|
49
|
|
|
$this->addSql(sprintf('ALTER TABLE %s.second_factor DROP PRIMARY KEY', $gatewaySchema)); |
50
|
|
|
$this->addSql(sprintf('ALTER TABLE %s.second_factor ADD PRIMARY KEY (id)', $gatewaySchema)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
private function getGatewaySchema() |
57
|
|
|
{ |
58
|
|
|
return $this->container->getParameter('database_gateway_name'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|