Passed
Pull Request — master (#19612)
by Fedonyuk
09:46
created

m160313_153426_session_init   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 39
ccs 18
cts 21
cp 0.8571
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 3 1
A up() 0 26 6
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
use yii\db\Migration;
9
10
/**
11
 * Initializes Session tables.
12
 *
13
 * @author Misbahul D Munir <[email protected]>
14
 * @since 2.0.8
15
 */
16
class m160313_153426_session_init extends Migration
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 30
    public function up()
22
    {
23 30
        $dataType = $this->binary();
24 30
        $tableOptions = null;
25
26 30
        switch ($this->db->driverName) {
27 30
            case 'mysql':
28
                // https://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
29 10
                $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
30 10
                break;
31 20
            case 'sqlsrv':
32 20
            case 'mssql':
33 20
            case 'dblib':
34
                // "varbinary(max)" added in SQL Server 2012 (version 11.0.0)
35
                if (version_compare($this->getDb()->getServerVersion(), '11.0.0') < 0) {
36
                    $dataType = $this->text();
37
                }
38
                break;
39
        }
40
41 30
        $this->createTable('{{%session}}', [
42 30
            'id' => $this->string()->notNull(),
43 30
            'expire' => $this->integer(),
44 30
            'data' => $dataType,
45 30
            'PRIMARY KEY ([[id]])',
46
        ], $tableOptions);
47 30
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 30
    public function down()
53
    {
54 30
        $this->dropTable('{{%session}}');
55 30
    }
56
}
57