m160724_162347_artbox_comment.php
2.6 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
54
<?php
use yii\db\Migration;
class m160724_162347_artbox_comment extends Migration
{
    public function up()
    {
        $this->createTable('{{%artbox_comment}}', [
            'artbox_comment_id' => $this->primaryKey(),
            'text' => $this->text()->notNull(),
            'user_id' => $this->integer(),
            'username' => $this->string(),
            'email' => $this->string(),
            'date_add' => $this->integer()->notNull(),
            'date_update' => $this->integer()->notNull(),
            'date_delete' => $this->integer(),
            'status' => $this->integer()->notNull()->defaultValue(1),
            'artbox_comment_pid' => $this->integer(),
            'related_id' => $this->integer(),
            'ip' => $this->string()->notNull(),
            'info' => $this->text(),
        ]);
    
        $this->addForeignKey('user_id_user', '{{%artbox_comment}}', 'user_id', 'customer', 'id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('artbox_comment_pid_artbox_comment', '{{%artbox_comment}}', 'artbox_comment_pid', 'artbox_comment', 'artbox_comment_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('related_id_artbox_comment', '{{%artbox_comment}}', 'related_id', 'artbox_comment', 'artbox_comment_id', 'CASCADE', 'CASCADE');
        
        $this->createTable('{{%artbox_like}}', [
            'artbox_like_id' => $this->primaryKey(),
            'artbox_comment_id' => $this->integer()->notNull(),
            'user_id' => $this->integer(),
            'date_add' => $this->integer()->notNull(),
            'is_like' => $this->integer()->notNull()->defaultValue(1),
        ]);
    
        $this->addForeignKey('artbox_comment_id_artbox_comment', '{{%artbox_like}}', 'artbox_comment_id', 'artbox_comment', 'artbox_comment_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('user_id_user', '{{%artbox_like}}', 'user_id', 'customer', 'id', 'CASCADE', 'CASCADE');
        $this->createIndex('artbox_like_unique', '{{%artbox_like}}', ['artbox_comment_id', 'user_id', 'is_like'], true);
    
    }
    public function down()
    {
        $this->dropForeignKey('user_id_user', '{{%artbox_comment}}');
        $this->dropForeignKey('artbox_comment_pid_artbox_comment', '{{%artbox_comment}}');
        $this->dropForeignKey('related_id_artbox_comment', '{{%artbox_comment}}');
        $this->dropForeignKey('artbox_comment_id_artbox_comment', '{{%artbox_like}}');
        $this->dropForeignKey('user_id_user', '{{%artbox_like}}');
        $this->dropIndex('artbox_like_unique', '{{%artbox_like}}');
        $this->dropTable('{{%artbox_comment}}');
        $this->dropTable('{{%artbox_like}}');
    }
} 
