Completed
Push — feature/test-php-7-2-in-travis ( 027341...a56bae )
by
unknown
05:31
created

Version20150508085838   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 4 1
A up() 0 15 1
A down() 0 12 1
A getGatewaySchema() 0 4 1
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
 * Auto-generated Migration: Please modify to your needs!
12
 */
13
class Version20150508085838 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 ADD COLUMN uuid VARCHAR(36) DEFAULT NULL', $gatewaySchema));
36
        $this->addSql(sprintf('UPDATE %s.second_factor set uuid = UUID() WHERE 1 = 1', $gatewaySchema));
37
        $this->addSql(sprintf('ALTER TABLE %s.second_factor CHANGE id id INT NOT NULL', $gatewaySchema));
38
        $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP PRIMARY KEY', $gatewaySchema));
39
        $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP COLUMN id', $gatewaySchema));
40
        $this->addSql(sprintf('ALTER TABLE %s.second_factor CHANGE uuid id VARCHAR(36) NOT NULL', $gatewaySchema));
41
        $this->addSql(sprintf('ALTER TABLE %s.second_factor ADD PRIMARY KEY (id)', $gatewaySchema));
42
    }
43
44
    /**
45
     * @param Schema $schema
46
     */
47
    public function down(Schema $schema)
48
    {
49
        // this down() migration is auto-generated, please modify it to your needs
50
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
51
52
        $gatewaySchema = $this->getGatewaySchema();
53
54
        $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP PRIMARY KEY', $gatewaySchema));
55
        $this->addSql(sprintf('ALTER TABLE %s.second_factor CHANGE id uuid VARCHAR(36)', $gatewaySchema));
56
        $this->addSql(sprintf('ALTER TABLE %s.second_factor ADD id INT PRIMARY KEY AUTO_INCREMENT', $gatewaySchema));
57
        $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP COLUMN uuid', $gatewaySchema));
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    private function getGatewaySchema()
64
    {
65
        return $this->container->getParameter('database_gateway_name');
66
    }
67
}
68