Blame view

migrations/m160724_162347_artbox_comment.php 4.28 KB
a2cde075   Yarik   first commit
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  <?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(),
                      'created_at'         => $this->integer()
                                                   ->notNull(),
                      'updated_at'         => $this->integer()
                                                   ->notNull(),
                      'deleted_at'         => $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(),
                      'created_at'        => $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}}');
          }
      }