Version20220519134637   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 34
dl 0
loc 61
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 37 1
A down() 0 16 1
1
<?php
2
3
/**
4
 * Copyright 2022 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
declare(strict_types=1);
20
21
namespace Surfnet\Migrations;
22
23
use Doctrine\DBAL\Schema\Schema;
24
use Doctrine\Migrations\AbstractMigration;
25
use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationInterface;
26
use Surfnet\Stepup\MigrationsFactory\ConfigurationAwareMigrationTrait;
27
28
/**
29
 * Adds the Self asserted tokens feature to the middleware and gateway databases
30
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
31
final class Version20220519134637 extends AbstractMigration implements ConfigurationAwareMigrationInterface
32
{
33
    use ConfigurationAwareMigrationTrait;
34
35
    public function up(Schema $schema): void
36
    {
37
        // this up() migration is auto-generated, please modify it to your needs
38
        $this->abortIf(
39
            $this->connection->getDatabasePlatform()->getName() !== 'mysql',
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Platforms\...ractPlatform::getName() has been deprecated: Identify platforms by their class. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
            /** @scrutinizer ignore-deprecated */ $this->connection->getDatabasePlatform()->getName() !== 'mysql',

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
40
            'Migration can only be executed safely on \'mysql\'.',
41
        );
42
        $this->addSql(
43
            'ALTER TABLE institution_configuration_options ADD self_asserted_tokens_option INT DEFAULT \'0\' NOT NULL',
44
        );
45
        $this->addSql(
46
            'CREATE TABLE recovery_token (id VARCHAR(36) NOT NULL, identity_id VARCHAR(36) NOT NULL, type VARCHAR(16) NOT NULL, recovery_method_identifier VARCHAR(255) NOT NULL, INDEX idx_recovery_method_type (type), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB',
47
        );
48
        $this->addSql(
49
            'CREATE TABLE identity_self_asserted_token_options (identity_id VARCHAR(36) NOT NULL, possessed_token TINYINT(1) NOT NULL, possessed_self_asserted_token TINYINT(1) NOT NULL, PRIMARY KEY(identity_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB',
50
        );
51
        // The unknown vetting type is set on the vetted_second_factor::vetting_type column for the existing second
52
        // factors. This to inform consumers of the projection, that the vetting type was recorded at a time before we
53
        // tracked the vetting type of the vetted second factors. It is safe to assume the vetting type is either
54
        // on-premise or self-vetted (both vetting types where the identity of the user was verified at the service desk
55
        // at some point).
56
        $this->addSql('ALTER TABLE vetted_second_factor ADD vetting_type VARCHAR(255) DEFAULT \'unknown\'');
57
        $this->addSql(
58
            'ALTER TABLE recovery_token ADD institution VARCHAR(255) NOT NULL, ADD name VARCHAR(255) NOT NULL, ADD email VARCHAR(255) NOT NULL, ADD status INT NOT NULL',
59
        );
60
        $this->addSql(
61
            'ALTER TABLE audit_log ADD recovery_token_identifier VARCHAR(255) DEFAULT NULL, ADD recovery_token_type VARCHAR(36) DEFAULT NULL',
62
        );
63
        $this->addSql(
64
            'CREATE TABLE vetting_type_hint (institution VARCHAR(36) NOT NULL, hints LONGTEXT NOT NULL, PRIMARY KEY(institution)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB',
65
        );
66
67
        $gatewaySchema = $this->getGatewaySchema();
68
        $this->addSql(
69
            sprintf(
70
                'ALTER TABLE %s.second_factor ADD identity_vetted TINYINT(1) DEFAULT \'1\'',
71
                $gatewaySchema,
72
            ),
73
        );
74
    }
75
76
    public function down(Schema $schema): void
77
    {
78
        // this down() migration is auto-generated, please modify it to your needs
79
        $this->abortIf(
80
            $this->connection->getDatabasePlatform()->getName() !== 'mysql',
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Platforms\...ractPlatform::getName() has been deprecated: Identify platforms by their class. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

80
            /** @scrutinizer ignore-deprecated */ $this->connection->getDatabasePlatform()->getName() !== 'mysql',

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
81
            'Migration can only be executed safely on \'mysql\'.',
82
        );
83
        $this->addSql('ALTER TABLE institution_configuration_options DROP self_asserted_tokens_option');
84
        $this->addSql('DROP TABLE recovery_token');
85
        $this->addSql('DROP TABLE identity_self_asserted_token_options');
86
        $this->addSql('ALTER TABLE vetted_second_factor DROP vetting_type');
87
        $this->addSql('ALTER TABLE audit_log DROP recovery_token_identifier, DROP recovery_token_type');
88
        $this->addSql('DROP TABLE vetting_type_hint');
89
90
        $gatewaySchema = $this->getGatewaySchema();
91
        $this->addSql(sprintf('ALTER TABLE %s.second_factor DROP identity_vetted', $gatewaySchema));
92
    }
93
}
94