Completed
Pull Request — master (#361)
by
unknown
03:09
created

safeDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Migration\Session;
13
14
use Da\User\Helper\MigrationHelper;
15
use yii\db\Migration;
16
17
18
class m000000_000001_create_session_history_table extends Migration
19
{
20
    const SESSION_HISTORY_TABLE = '{{%session_history}}';
21
    const USER_TABLE = '{{%user}}';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function safeUp()
27
    {
28
        $this->createTable(self::SESSION_HISTORY_TABLE, [
29
            'user_id' => $this->integer(),
30
            'session_id' => $this->string()->null(),
31
            'user_agent' => $this->string()->notNull(),
32
            'ip' => $this->string(45)->notNull(),
33
            'created_at' => $this->integer()->notNull(),
34
            'updated_at' => $this->integer()->notNull(),
35
        ]);
36
37
        $this->createIndex(
38
            '{{%session_history_user_id}}',
39
            self::SESSION_HISTORY_TABLE,
40
            ['user_id']
41
        );
42
43
        $this->createIndex(
44
            '{{%session_history_session_id}}',
45
            self::SESSION_HISTORY_TABLE,
46
            ['session_id']
47
        );
48
49
        $this->createIndex(
50
            '{{%session_history_updated_at}}',
51
            self::SESSION_HISTORY_TABLE,
52
            ['updated_at']
53
        );
54
55
        $this->addForeignKey(
56
            '{{%fk_user_session_history}}',
57
            self::SESSION_HISTORY_TABLE,
58
            'user_id',
59
            self::USER_TABLE,
60
            'id',
61
            'CASCADE',
62
            MigrationHelper::isMicrosoftSQLServer($this->db->driverName) ? 'NO ACTION' : 'RESTRICT'
63
        );
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function safeDown()
70
    {
71
        $this->dropTable(self::SESSION_HISTORY_TABLE);
72
    }
73
}
74