Completed
Push — develop ( 68a31f...553b36 )
by Mario
01:37
created

Version0_14_0   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 15 2
A down() 0 20 2
1
<?php
2
3
namespace AppBundle\Migrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
use Ds\Component\Container\Attribute;
8
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9
use stdClass;
10
11
/**
12
 * Class Version0_14_0
13
 */
14
class Version0_14_0 extends AbstractMigration implements ContainerAwareInterface
15
{
16
    use Attribute\Container;
17
18
    /**
19
     * Up
20
     *
21
     * @param \Doctrine\DBAL\Schema\Schema $schema
22
     */
23
    public function up(Schema $schema)
24
    {
25
        $platform = $this->connection->getDatabasePlatform()->getName();
26
27
        switch ($platform) {
28
            case 'postgresql':
29
                // Schema
30
                $this->addSql('ALTER TABLE ds_tenant DROP data');
31
                break;
32
33
            default:
34
                $this->abortIf(true,'Migration cannot be executed on "'.$platform.'".');
35
                break;
36
        }
37
    }
38
39
    /**
40
     * Down
41
     *
42
     * @param \Doctrine\DBAL\Schema\Schema $schema
43
     */
44
    public function down(Schema $schema)
45
    {
46
        $platform = $this->connection->getDatabasePlatform()->getName();
47
        $cipherService = $this->container->get('ds_encryption.service.cipher');
48
49
        switch ($platform) {
50
            case 'postgresql':
51
                // Schema
52
                $this->warnIf(true, 'Tenant data column was lost during the previous migration and was reset to an empty object.');
53
                $this->addSql('ALTER TABLE ds_tenant ADD data JSON NULL');
54
                $data = '"'.$cipherService->encrypt(serialize(new stdClass)).'"';
55
                $this->addSql('UPDATE ds_tenant SET data = '.$this->connection->quote($data));
56
                $this->addSql('ALTER TABLE ds_tenant ALTER COLUMN data SET NOT NULL');
57
                break;
58
59
            default:
60
                $this->abortIf(true,'Migration cannot be executed on "'.$platform.'".');
61
                break;
62
        }
63
    }
64
}
65