Blame view

migrations/m160724_162347_artbox_comment.php 3.91 KB
a2cde075   Yarik   first commit
1
2
3
4
5
6
7
8
9
10
11
12
  <?php
      
      use yii\db\Migration;
      
      class m160724_162347_artbox_comment extends Migration
      {
          
          public function up()
          {
              $this->createTable(
                  '{{%artbox_comment}}',
                  [
faff2c48   Yarik   Artbox comment cr...
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
                      'id'          => $this->primaryKey(),
                      'text'        => $this->text()
                                            ->notNull(),
                      'customer_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),
                      'parent_id'   => $this->integer(),
                      'related_id'  => $this->integer(),
                      'ip'          => $this->string()
                                            ->notNull(),
                      'info'        => $this->text(),
                      'entity'      => $this->string()
                                            ->notNull()
                                            ->defaultValue(''),
                      'entity_id'   => $this->integer()
                                            ->notNull()
                                            ->defaultValue(1),
a2cde075   Yarik   first commit
38
39
40
41
                  ]
              );
              
              $this->addForeignKey(
faff2c48   Yarik   Artbox comment cr...
42
                  'parent_id_artbox_comment',
a2cde075   Yarik   first commit
43
                  '{{%artbox_comment}}',
faff2c48   Yarik   Artbox comment cr...
44
                  'parent_id',
a2cde075   Yarik   first commit
45
                  'artbox_comment',
faff2c48   Yarik   Artbox comment cr...
46
                  'id',
a2cde075   Yarik   first commit
47
48
49
50
51
52
53
54
                  'CASCADE',
                  'CASCADE'
              );
              $this->addForeignKey(
                  'related_id_artbox_comment',
                  '{{%artbox_comment}}',
                  'related_id',
                  'artbox_comment',
faff2c48   Yarik   Artbox comment cr...
55
                  'id',
a2cde075   Yarik   first commit
56
57
58
59
60
61
62
                  'CASCADE',
                  'CASCADE'
              );
              
              $this->createTable(
                  '{{%artbox_like}}',
                  [
faff2c48   Yarik   Artbox comment cr...
63
                      'id'                => $this->primaryKey(),
a2cde075   Yarik   first commit
64
65
                      'artbox_comment_id' => $this->integer()
                                                  ->notNull(),
faff2c48   Yarik   Artbox comment cr...
66
                      'customer_id'       => $this->integer(),
a2cde075   Yarik   first commit
67
68
69
70
71
72
73
74
75
76
77
78
79
                      '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',
faff2c48   Yarik   Artbox comment cr...
80
                  'id',
a2cde075   Yarik   first commit
81
82
83
                  'CASCADE',
                  'CASCADE'
              );
a2cde075   Yarik   first commit
84
85
86
87
88
              $this->createIndex(
                  'artbox_like_unique',
                  '{{%artbox_like}}',
                  [
                      'artbox_comment_id',
faff2c48   Yarik   Artbox comment cr...
89
                      'customer_id',
a2cde075   Yarik   first commit
90
91
92
93
94
95
96
97
98
                      'is_like',
                  ],
                  true
              );
              
          }
          
          public function down()
          {
faff2c48   Yarik   Artbox comment cr...
99
              $this->dropForeignKey('parent_id_artbox_comment', '{{%artbox_comment}}');
a2cde075   Yarik   first commit
100
101
              $this->dropForeignKey('related_id_artbox_comment', '{{%artbox_comment}}');
              $this->dropForeignKey('artbox_comment_id_artbox_comment', '{{%artbox_like}}');
a2cde075   Yarik   first commit
102
103
104
105
106
              $this->dropIndex('artbox_like_unique', '{{%artbox_like}}');
              $this->dropTable('{{%artbox_comment}}');
              $this->dropTable('{{%artbox_like}}');
          }
      }