m160620_131811_vote   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 22
dl 0
loc 31
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 23 1
A down() 0 4 1
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