Passed
Push — master ( 02be02...16ebe1 )
by Aleksandr
04:27
created

m161228_100819_init::safeDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
class m161228_100819_init extends \yii\db\Migration
4
{
5
    use \carono\yii2migrate\traits\MigrationTrait;
6
7
    public $tableName = '{{%file_upload}}';
8
9
    public function newTables()
10
    {
11
        return [
12
            $this->tableName => [
13
                'id' => self::primaryKey(),
0 ignored issues
show
Bug Best Practice introduced by
The method yii\db\Migration::primaryKey() is not static, but was called statically. ( Ignorable by Annotation )

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

13
                'id' => self::/** @scrutinizer ignore-call */ primaryKey(),
Loading history...
14
                'uid' => self::string(32)->unique()->comment('Уникальный идентификатор, используется для содания директорий хранения'),
0 ignored issues
show
Bug Best Practice introduced by
The method yii\db\Migration::string() is not static, but was called statically. ( Ignorable by Annotation )

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

14
                'uid' => self::/** @scrutinizer ignore-call */ string(32)->unique()->comment('Уникальный идентификатор, используется для содания директорий хранения'),
Loading history...
15
                'user_id' => self::integer()->comment('Текущий пользователь, который сохраняет файл'),
0 ignored issues
show
Bug Best Practice introduced by
The method yii\db\Migration::integer() is not static, but was called statically. ( Ignorable by Annotation )

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

15
                'user_id' => self::/** @scrutinizer ignore-call */ integer()->comment('Текущий пользователь, который сохраняет файл'),
Loading history...
16
                'name' => self::string()->comment('Имя файла, без расширения'),
17
                'extension' => self::string()->comment('Расширение'),
18
                'folder' => self::string()->comment('Папка, где хранится файл, можно использовать @алиасы'),
19
                'mime_type' => self::string()->comment('Mime Type по содержимому файла'),
20
                'size' => self::integer()->comment('Размер файла'),
21
                'data' => self::text()->comment('Произвольные данные'),
0 ignored issues
show
Bug Best Practice introduced by
The method yii\db\Migration::text() is not static, but was called statically. ( Ignorable by Annotation )

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

21
                'data' => self::/** @scrutinizer ignore-call */ text()->comment('Произвольные данные'),
Loading history...
22
                'session' => self::string()->comment('Сессия текущего пользователя'),
23
                'md5' => self::string(32)->comment('MD5 по содержимому файла'),
24
                'slug' => self::string()->comment('Произвольный слаг'),
25
                'is_active' => self::boolean()->notNull()->defaultValue(true),
0 ignored issues
show
Bug Best Practice introduced by
The method yii\db\Migration::boolean() is not static, but was called statically. ( Ignorable by Annotation )

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

25
                'is_active' => self::/** @scrutinizer ignore-call */ boolean()->notNull()->defaultValue(true),
Loading history...
26
                'is_exist' => self::boolean()->notNull()->defaultValue(true)->comment('Существование реального файла'),
27
                'binary' => self::binary()->comment('Файл хранится в базе (на данный момент не используется)'),
0 ignored issues
show
Bug Best Practice introduced by
The method yii\db\Migration::binary() is not static, but was called statically. ( Ignorable by Annotation )

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

27
                'binary' => self::/** @scrutinizer ignore-call */ binary()->comment('Файл хранится в базе (на данный момент не используется)'),
Loading history...
28
                'created_at' => self::dateTime()->comment('Дата создания'),
0 ignored issues
show
Bug Best Practice introduced by
The method yii\db\Migration::dateTime() is not static, but was called statically. ( Ignorable by Annotation )

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

28
                'created_at' => self::/** @scrutinizer ignore-call */ dateTime()->comment('Дата создания'),
Loading history...
29
                'updated_at' => self::dateTime()->comment('Дата обновления')
30
            ]
31
        ];
32
    }
33
34
    public function newIndex()
35
    {
36
        return [
37
            [$this->tableName, ['is_active', 'is_exist']],
38
            [$this->tableName, 'slug'],
39
        ];
40
    }
41
42
    public function safeUp()
43
    {
44
        if ($this->db->driverName === 'mysql') {
45
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
46
        } else {
47
            $tableOptions = null;
48
        }
49
        $this->upNewTables([], $tableOptions);
0 ignored issues
show
Bug introduced by
It seems like $tableOptions can also be of type string; however, parameter $tableOptions of m161228_100819_init::upNewTables() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

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

49
        $this->upNewTables([], /** @scrutinizer ignore-type */ $tableOptions);
Loading history...
50
        $this->upNewIndex();
51
    }
52
53
    public function safeDown()
54
    {
55
        $this->downNewTables();
56
    }
57
}
58