Completed
Push — master ( f57602...4c0e5b )
by Emmanuel
06:53
created

CreateTicketsTable::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreateTicketsTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create(config('laravel-tickets.database.tickets-table'), function (Blueprint $table) {
17
            $table->id();
18
            $table->unsignedBigInteger('user_id');
19
            $table->string('subject');
20
            $table->enum('priority', config('laravel-tickets.priorities'));
21
            $table->enum('state', [ 'OPEN', 'ANSWERED', 'CLOSED' ])->default('OPEN');
22
            $table->timestamps();
23
24
            $table->foreign('user_id')->on(config('laravel-tickets.database.users-table'))->references('id');
25
        });
26
27
        Schema::create(config('laravel-tickets.database.ticket-messages-table'), function (Blueprint $table) {
28
            $table->id();
29
            $table->unsignedBigInteger('ticket_id');
30
            $table->unsignedBigInteger('user_id');
31
            $table->text('message');
32
            $table->timestamps();
33
34
            $table->foreign('user_id')->on(config('laravel-tickets.database.users-table'))->references('id');
35
            $table->foreign('ticket_id')->on(config('laravel-tickets.database.tickets-table'))->references('id');
36
        });
37
38
        Schema::create(config('laravel-tickets.database.ticket-uploads-table'), function (Blueprint $table) {
39
            $table->id();
40
            $table->unsignedBigInteger('ticket_message_id');
41
            $table->string('path');
42
            $table->timestamps();
43
44
            $table->foreign('ticket_message_id')->on(config('laravel-tickets.database.ticket-messages-table'))->references('id');
45
        });
46
    }
47
48
    /**
49
     * Reverse the migrations.
50
     *
51
     * @return void
52
     */
53
    public function down()
54
    {
55
        Schema::dropIfExists(config('laravel-tickets.database.tickets-table'));
56
        Schema::dropIfExists(config('laravel-tickets.database.ticket-messages-table'));
57
        Schema::dropIfExists(config('laravel-tickets.database.ticket-uploads-table'));
58
    }
59
}
60