M180807000000Schema::safeUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 44
c 3
b 0
f 0
dl 0
loc 51
rs 9.216
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @link https://github.com/zhuravljov/yii2-queue-monitor
4
 * @copyright Copyright (c) 2017 Roman Zhuravlev
5
 * @license http://opensource.org/licenses/BSD-3-Clause
6
 */
7
8
namespace zhuravljov\yii\queue\monitor\migrations;
9
10
use zhuravljov\yii\queue\monitor\base\Migration;
11
12
/**
13
 * Storage Schema
14
 *
15
 * @author Roman Zhuravlev <[email protected]>
16
 */
17
class M180807000000Schema extends Migration
18
{
19
    /**
20
     * @inheritdoc
21
     */
22
    public function safeUp()
23
    {
24
        $this->createTable($this->env->pushTableName, [
25
            'id' => $this->bigPrimaryKey(),
26
            'parent_id' => $this->bigInteger(),
27
            'sender_name' => $this->string(32)->notNull(),
28
            'job_uid' => $this->string(32)->notNull(),
29
            'job_class' => $this->string()->notNull(),
30
            'job_data' => $this->binary()->notNull(),
31
            'ttr' => $this->integer()->unsigned()->notNull(),
32
            'delay' => $this->integer()->unsigned()->notNull(),
33
            'trace' => $this->text(),
34
            'context' => $this->text(),
35
            'pushed_at' => $this->integer()->unsigned()->notNull(),
36
            'stopped_at' => $this->integer()->unsigned(),
37
            'first_exec_id' => $this->bigInteger(),
38
            'last_exec_id' => $this->bigInteger(),
39
        ]);
40
        $this->createIndex('ind_qp_parent_id', $this->env->pushTableName, 'parent_id');
41
        $this->createIndex('ind_qp_job_uid', $this->env->pushTableName, ['sender_name', 'job_uid']);
42
        $this->createIndex('ind_qp_job_class', $this->env->pushTableName, 'job_class');
43
        $this->createIndex('ind_qp_first_exec_id', $this->env->pushTableName, 'first_exec_id');
44
        $this->createIndex('ind_qp_last_exec_id', $this->env->pushTableName, 'last_exec_id');
45
46
        $this->createTable($this->env->execTableName, [
47
            'id' => $this->bigPrimaryKey(),
48
            'push_id' => $this->bigInteger()->notNull(),
49
            'worker_id' => $this->bigInteger(),
50
            'attempt' => $this->integer()->unsigned()->notNull(),
51
            'started_at' => $this->integer()->unsigned()->notNull(),
52
            'finished_at' => $this->integer()->unsigned(),
53
            'memory_usage' => $this->bigInteger()->unsigned(),
54
            'error' => $this->text(),
55
            'retry' => $this->boolean(),
56
        ]);
57
        $this->createIndex('ind_qe_push_id', $this->env->execTableName, 'push_id');
58
        $this->createIndex('ind_qe_worker_id', $this->env->execTableName, 'worker_id');
59
60
        $this->createTable($this->env->workerTableName, [
61
            'id' => $this->bigPrimaryKey(),
62
            'sender_name' => $this->string(32)->notNull(),
63
            'host' => $this->string(64),
64
            'pid' => $this->integer()->unsigned(),
65
            'started_at' => $this->integer()->unsigned()->notNull(),
66
            'pinged_at' => $this->integer()->unsigned()->notNull(),
67
            'stopped_at' => $this->integer()->unsigned(),
68
            'finished_at' => $this->integer()->unsigned(),
69
            'last_exec_id' => $this->bigInteger(),
70
        ]);
71
        $this->createIndex('ind_qw_finished_at', $this->env->workerTableName, 'finished_at');
72
        $this->createIndex('ind_qw_last_exec_id', $this->env->workerTableName, 'last_exec_id');
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78
    public function safeDown()
79
    {
80
        $this->dropTable($this->env->workerTableName);
81
        $this->dropTable($this->env->execTableName);
82
        $this->dropTable($this->env->pushTableName);
83
    }
84
}
85