|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use yii\db\Expression; |
|
4
|
|
|
use yii\db\Schema; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class m000000_000014_post_comment |
|
8
|
|
|
* |
|
9
|
|
|
* @author Agiel K. Saputra <[email protected]> |
|
10
|
|
|
* @since 0.1.0 |
|
11
|
|
|
*/ |
|
12
|
|
|
class m000000_000014_post_comment extends \yii\db\Migration |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @inheritdoc |
|
16
|
|
|
*/ |
|
17
|
|
|
public function up() |
|
18
|
|
|
{ |
|
19
|
|
|
$tableOptions = null; |
|
20
|
|
|
|
|
21
|
|
|
if ($this->db->driverName === 'mysql') { |
|
22
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$this->createTable('{{%post_comment}}', [ |
|
26
|
|
|
'id' => Schema::TYPE_PK, |
|
27
|
|
|
'post_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', |
|
28
|
|
|
'author' => Schema::TYPE_TEXT, |
|
29
|
|
|
'email' => Schema::TYPE_STRING . '(100)', |
|
30
|
|
|
'url' => Schema::TYPE_STRING . '(255)', |
|
31
|
|
|
'ip' => Schema::TYPE_STRING . '(100) NOT NULL', |
|
32
|
|
|
'date' => Schema::TYPE_DATETIME . ' NOT NULL', |
|
33
|
|
|
'content' => Schema::TYPE_TEXT . ' NOT NULL', |
|
34
|
|
|
'status' => Schema::TYPE_STRING . '(20) NOT NULL', |
|
35
|
|
|
'agent' => Schema::TYPE_STRING . '(255) NOT NULL', |
|
36
|
|
|
'parent' => Schema::TYPE_INTEGER . '(11) DEFAULT 0', |
|
37
|
|
|
'user_id' => Schema::TYPE_INTEGER . '(11)', |
|
38
|
|
|
'FOREIGN KEY ([[post_id]]) REFERENCES {{%post}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE', |
|
39
|
|
|
], $tableOptions); |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Insert first comment for first post |
|
43
|
|
|
*/ |
|
44
|
|
|
$this->insert('{{%post_comment}}', [ |
|
45
|
|
|
'post_id' => 1, |
|
46
|
|
|
'author' => 'WD, WritesDown', |
|
47
|
|
|
'email' => '[email protected]', |
|
48
|
|
|
'url' => 'http://www.writesdown.com/', |
|
49
|
|
|
'ip' => '', |
|
50
|
|
|
'date' => new Expression('NOW()'), |
|
51
|
|
|
'content' => 'SAMPLE COMMENT: Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris.', |
|
52
|
|
|
'status' => 'approved', |
|
53
|
|
|
'agent' => '', |
|
54
|
|
|
]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @inheritdoc |
|
59
|
|
|
*/ |
|
60
|
|
|
public function down() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->dropTable('{{%post_comment}}'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.