Completed
Pull Request — master (#24)
by Anton
02:57 queued 39s
created

CreateLoveReactionsTable::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
dl 0
loc 45
rs 9.328
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Laravel Love.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
use Illuminate\Database\Migrations\Migration;
15
use Illuminate\Database\Schema\Blueprint;
16
use Illuminate\Support\Facades\Schema;
17
18
final class CreateLoveReactionsTable extends Migration
19
{
20
    /**
21
     * Run the migrations.
22
     *
23
     * @return void
24
     */
25
    public function up(): void
26
    {
27
        Schema::create('love_reactions', function (Blueprint $table) {
28
            $table->bigIncrements('id');
29
            $table->unsignedBigInteger('reactant_id');
30
            $table->unsignedBigInteger('reacter_id');
31
            $table->unsignedBigInteger('reaction_type_id');
32
            $table->timestamps();
33
34
            $table->index('reactant_id');
35
            $table->index('reacter_id');
36
            $table->index('reaction_type_id');
37
            $table->index([
38
                'reactant_id',
39
                'reaction_type_id',
40
            ]);
41
            $table->index([
42
                'reactant_id',
43
                'reacter_id',
44
                'reaction_type_id',
45
            ]);
46
            $table->index([
47
                'reactant_id',
48
                'reacter_id',
49
            ]);
50
            $table->index([
51
                'reacter_id',
52
                'reaction_type_id',
53
            ]);
54
55
            $table
56
                ->foreign('reactant_id')
57
                ->references('id')
58
                ->on('love_reactants')
59
                ->onDelete('cascade');
60
            $table
61
                ->foreign('reacter_id')
62
                ->references('id')
63
                ->on('love_reacters')
64
                ->onDelete('cascade');
65
            $table
66
                ->foreign('reaction_type_id')
67
                ->references('id')
68
                ->on('love_reaction_types')
69
                ->onDelete('cascade');
70
        });
71
    }
72
73
    /**
74
     * Reverse the migrations.
75
     *
76
     * @return void
77
     */
78
    public function down(): void
79
    {
80
        Schema::dropIfExists('love_reactions');
81
    }
82
}
83