m160301_105759_chat.php
1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
use yii\db\Migration;
class m160301_105759_chat extends Migration
{
    public function up()
    {
        $this->createTable('{{%chat}}', [
            'chat_id' => $this->primaryKey(),
            'status' => $this->integer(),
            'comment' => $this->text(),
            'from_user' => $this->integer(),
            'to_user' => $this->integer(),
        ]);
        $this->createTable('{{%file}}', [
            'file_id' => $this->primaryKey(),
            'status' => $this->integer(),
            'name' => $this->string(50),
            'dir' => $this->string(255)
        ]);
        $this->createTable('{{%message}}', [
            'message_id' => $this->primaryKey(),
            'chat_id' => $this->integer(),
            'user_id' => $this->integer(),
            'status' => $this->integer(),
            'text' => $this->text(),
            'files' => $this->string(255),
            'date' => $this->timestamp()->defaultExpression('NOW()'),
        ]);
        $this->addForeignKey('chat_from_user', '{{%chat}}', 'from_user', '{{%user}}', 'id', 'SET NULL', 'NO ACTION');
        $this->addForeignKey('chat_to_user', '{{%chat}}', 'to_user', '{{%user}}', 'id', 'SET NULL', 'NO ACTION');
        $this->addForeignKey('message_to_chat', '{{%message}}', 'chat_id', '{{%chat}}', 'chat_id', 'CASCADE', 'CASCADE');
    }
    public function down()
    {
        $this->dropForeignKey('chat_from_user', '{{%chat}}');
        $this->dropForeignKey('chat_to_user', '{{%chat}}');
        $this->dropForeignKey('message_to_chat', '{{%message}}');
        $this->dropTable('{{%chat}}');
        $this->dropTable('{{%file}}');
        $this->dropTable('{{%message}}');
    }
}