Passed
Push — master ( 073721...924750 )
by Robin
02:35
created

CreateQueueTables::up()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 29
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 23
nc 5
nop 0
dl 0
loc 29
rs 9.552
c 1
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
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.database.failed.database');
18
            if (!Schema::connection($connection)->hasTable(config('queue.database.failed.table'))) {
19
                Schema::connection($connection)->create(
20
                    config('queue.database.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.database.failed.database');
58
            Schema::connection($connection)->dropIfExists(config('queue.connections.database.table'));
59
            Schema::connection($connection)->dropIfExists(config('queue.database.failed.table'));
60
        }
61
    }
62
}
63