Passed
Push — master ( c3d610...926549 )
by Marcel
02:48
created

Version020500Date20200815190000::changeSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 14
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OCA\Analytics\Migration;
6
7
use Closure;
8
use Doctrine\DBAL\Types\Type;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Types\Type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use OCP\DB\ISchemaWrapper;
10
use OCP\IDBConnection;
11
use OCP\Migration\IOutput;
12
use OCP\Migration\SimpleMigrationStep;
13
14
/**
15
 * Auto-generated migration step: Please modify to your needs!
16
 * sudo -u www-data php /var/www/nextcloud/occ migrations:execute analytics 020500Date20200815190000
17
 */
18
class Version020500Date20200815190000 extends SimpleMigrationStep
19
{
20
21
    /** @var IDBConnection */
22
    private $connection;
23
24
    public function __construct(IDBConnection $connection)
25
    {
26
        $this->connection = $connection;
27
    }
28
29
    /**
30
     * @param IOutput $output
31
     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
32
     * @param array $options
33
     */
34
    public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options)
35
    {
36
    }
37
38
    /**
39
     * @param IOutput $output
40
     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
41
     * @param array $options
42
     * @return null|ISchemaWrapper
43
     */
44
    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options)
45
    {
46
        /** @var Schema $schema */
47
        $schema = $schemaClosure();
48
        $table = $schema->getTable('analytics_threshold');
49
50
        $table->addColumn('value', Type::DECIMAL, [
51
            'notnull' => false,
52
            'precision' => 15,
53
            'scale' => 2,
54
            'default' => 0,
55
        ]);
56
57
        return $schema;
58
    }
59
60
    /**
61
     * @param IOutput $output
62
     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
63
     * @param array $options
64
     */
65
    public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options)
66
    {
67
        $query = $this->connection->getQueryBuilder();
68
        $query->update('analytics_threshold')
69
            ->set('value', 'dimension3');
70
        $query->execute();
71
    }
72
}
73