CreateQueueTables   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 28
dl 0
loc 53
rs 10
c 2
b 1
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 29 4
A down() 0 6 2
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreateQueueTables extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        if (config('queue.default') == 'database') {
17
            $connection = config('queue.failed.database');
18
            if (!Schema::connection($connection)->hasTable(config('queue.failed.table'))) {
19
                Schema::connection($connection)->create(
20
                    config('queue.failed.table'),
21
                    function (Blueprint $table) {
22
                        $table->bigIncrements('id');
23
                        $table->text('connection');
24
                        $table->text('queue');
25
                        $table->longText('payload');
26
                        $table->longText('exception');
27
                        $table->timestamp('failed_at')->useCurrent();
28
                    }
29
                );
30
            }
31
32
            if (!Schema::connection($connection)->hasTable(config('queue.connections.database.table'))) {
33
                Schema::connection($connection)->create(
34
                    config('queue.connections.database.table'),
35
                    function (Blueprint $table) {
36
                        $table->bigIncrements('id');
37
                        $table->string('queue')->index();
38
                        $table->longText('payload');
39
                        $table->unsignedTinyInteger('attempts');
40
                        $table->unsignedInteger('reserved_at')->nullable();
41
                        $table->unsignedInteger('available_at');
42
                        $table->unsignedInteger('created_at');
43
                    }
44
                );
45
            }
46
        }
47
    }
48
49
    /**
50
     * Reverse the migrations.
51
     *
52
     * @return void
53
     */
54
    public function down()
55
    {
56
        if (config('queue.default') == 'database') {
57
            $connection = config('queue.failed.database');
58
            Schema::connection($connection)->dropIfExists(config('queue.connections.database.table'));
59
            Schema::connection($connection)->dropIfExists(config('queue.failed.table'));
60
        }
61
    }
62
}
63