|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use hauntd\vote\migrations\Migration; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Alexander Kononenko <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
class m160620_131811_vote extends Migration |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
public function up() |
|
11
|
|
|
{ |
|
12
|
|
|
$this->createTable('{{%vote}}', [ |
|
13
|
|
|
'id' => $this->primaryKey(), |
|
14
|
|
|
'entity' => $this->integer()->unsigned()->notNull(), |
|
15
|
|
|
'target_id' => $this->integer()->notNull(), |
|
16
|
|
|
'user_id' => $this->integer(), |
|
17
|
|
|
'user_ip' => $this->string(39)->notNull()->defaultValue('127.0.0.1'), |
|
18
|
|
|
'value' => $this->smallInteger(1)->notNull(), |
|
19
|
|
|
'created_at' => $this->integer()->notNull(), |
|
20
|
|
|
]); |
|
21
|
|
|
$this->createTable('{{%vote_aggregate}}', [ |
|
22
|
|
|
'id' => $this->primaryKey(), |
|
23
|
|
|
'entity' => $this->integer()->unsigned()->notNull(), |
|
24
|
|
|
'target_id' => $this->integer()->notNull(), |
|
25
|
|
|
'positive' => $this->integer()->defaultValue(0), |
|
26
|
|
|
'negative' => $this->integer()->defaultValue(0), |
|
27
|
|
|
'rating' => $this->float()->unsigned()->notNull()->defaultValue(0), |
|
28
|
|
|
]); |
|
29
|
|
|
$this->createIndex('vote_target_idx', '{{%vote}}', ['entity', 'target_id'], false); |
|
30
|
|
|
$this->createIndex('vote_user_idx', '{{%vote}}', 'user_id', false); |
|
31
|
|
|
$this->createIndex('vote_user_ip_idx', '{{%vote}}', 'user_ip', false); |
|
32
|
|
|
$this->createIndex('vote_aggregate_target_idx', '{{%vote_aggregate}}', ['entity', 'target_id'], true); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function down() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->dropTable('{{%vote}}'); |
|
38
|
|
|
$this->dropTable('{{%vote_aggregate}}'); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
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.