Completed
Push — master ( 5d22bd...1f972f )
by Xu
04:52
created

m180305_014442_create_queue_table::safeUp()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 18
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 24
rs 8.9713
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * Handles the creation of table `queue`.
7
 */
8
class m180305_014442_create_queue_table extends Migration
9
{
10
    public $tableName = '{{%queue}}';
11
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function safeUp()
16
    {
17
        $tableOptions = null;
18
        if ($this->db->driverName === 'mysql') {
19
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
20
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
21
        }
22
23
        $this->createTable($this->tableName, [
24
            'id' => $this->bigPrimaryKey(),
25
            'channel' => $this->string()->notNull(),
26
            'job' => $this->binary()->notNull(),
27
            'pushed_at' => $this->integer()->unsigned()->notNull(),
28
            'ttr'=>$this->integer()->notNull()->unsigned(),
29
            'delay' => $this->integer()->unsigned()->defaultValue(0)->notNull(),
30
            'priority'=>$this->integer()->unsigned()->notNull()->defaultValue(1024),
31
            'reserved_at' => $this->integer()->unsigned(),
32
            'attempt'=>$this->integer()->unsigned(),
33
            'done_at' => $this->integer()->unsigned(),
34
        ], $tableOptions);
35
36
        $this->createIndex('channel', $this->tableName, 'channel');
37
        $this->createIndex('reserved_at', $this->tableName, 'reserved_at');
38
        $this->createIndex('priority', $this->tableName, 'priority');
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function safeDown()
45
    {
46
        $this->dropTable($this->tableName);
47
    }
48
}
49