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

CreateLoveReactantReactionCountersTable::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 23
dl 0
loc 27
rs 9.552
c 3
b 0
f 1
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 CreateLoveReactantReactionCountersTable extends Migration
19
{
20
    /**
21
     * Run the migrations.
22
     *
23
     * @return void
24
     */
25
    public function up(): void
26
    {
27
        Schema::create('love_reactant_reaction_counters', function (Blueprint $table) {
28
            $table->bigIncrements('id');
29
            $table->unsignedBigInteger('reactant_id');
30
            $table->unsignedBigInteger('reaction_type_id');
31
            $table->unsignedBigInteger('count')->default(0);
32
            $table->bigInteger('weight')->default(0);
33
            $table->timestamps();
34
35
            $table->index('reactant_id');
36
            $table->index('reaction_type_id');
37
            $table->index([
38
                'reactant_id',
39
                'reaction_type_id',
40
            ], 'love_reactant_reaction_counters_reactant_reaction_type_index');
41
42
            $table
43
                ->foreign('reactant_id')
44
                ->references('id')
45
                ->on('love_reactants')
46
                ->onDelete('cascade');
47
            $table
48
                ->foreign('reaction_type_id')
49
                ->references('id')
50
                ->on('love_reaction_types')
51
                ->onDelete('cascade');
52
        });
53
    }
54
55
    /**
56
     * Reverse the migrations.
57
     *
58
     * @return void
59
     */
60
    public function down(): void
61
    {
62
        Schema::dropIfExists('love_reactant_reaction_counters');
63
    }
64
}
65