26656179
Administrator
01.03.16
|
1
2
3
4
5
6
7
8
9
10
|
<?php
use yii\db\Migration;
class m160301_105759_chat extends Migration
{
public function up()
{
$this->createTable('{{%chat}}', [
'chat_id' => $this->primaryKey(),
|
6a97773c
Administrator
01.03.16
|
11
12
|
'status' => $this->integer(),
'comment' => $this->text(),
|
26656179
Administrator
01.03.16
|
13
14
15
16
|
'from_user' => $this->integer(),
'to_user' => $this->integer(),
]);
|
6a97773c
Administrator
01.03.16
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
$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()'),
]);
|
26656179
Administrator
01.03.16
|
38
39
|
$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');
|
6a97773c
Administrator
01.03.16
|
40
41
|
$this->addForeignKey('message_to_chat', '{{%message}}', 'chat_id', '{{%chat}}', 'chat_id', 'CASCADE', 'CASCADE');
|
26656179
Administrator
01.03.16
|
42
43
44
45
46
47
|
}
public function down()
{
$this->dropForeignKey('chat_from_user', '{{%chat}}');
$this->dropForeignKey('chat_to_user', '{{%chat}}');
|
6a97773c
Administrator
01.03.16
|
48
|
$this->dropForeignKey('message_to_chat', '{{%message}}');
|
26656179
Administrator
01.03.16
|
49
|
$this->dropTable('{{%chat}}');
|
6a97773c
Administrator
01.03.16
|
50
51
|
$this->dropTable('{{%file}}');
$this->dropTable('{{%message}}');
|
26656179
Administrator
01.03.16
|
52
53
|
}
}
|