Passed
Push — master ( 0a2dad...a9b714 )
by Anton
04:22 queued 01:15
created

CreateLoveReactantReactionCountersTable::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 25
rs 9.584
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 Cog\Laravel\Love\Reactant\ReactionCounter\Models\ReactionCounter;
15
use Cog\Laravel\Love\Support\Database\Migration;
16
use Illuminate\Database\Schema\Blueprint;
17
18
return new class extends Migration
19
{
20
    /**
21
     * Run the migrations.
22
     */
23
    public function up(): void
24
    {
25
        $this->schema->create((new ReactionCounter())->getTable(), function (Blueprint $table) {
26
            $table->bigIncrements('id');
27
            $table->unsignedBigInteger('reactant_id');
28
            $table->unsignedBigInteger('reaction_type_id');
29
            $table->unsignedBigInteger('count');
30
            $table->decimal('weight', 13, 2);
31
            $table->timestamps();
32
33
            $table->index([
34
                'reactant_id',
35
                'reaction_type_id',
36
            ], 'love_reactant_reaction_counters_reactant_reaction_type_index');
37
38
            $table
39
                ->foreign('reactant_id')
40
                ->references('id')
41
                ->on('love_reactants')
42
                ->onDelete('cascade');
43
            $table
44
                ->foreign('reaction_type_id')
45
                ->references('id')
46
                ->on('love_reaction_types')
47
                ->onDelete('cascade');
48
        });
49
    }
50
51
    /**
52
     * Reverse the migrations.
53
     */
54
    public function down(): void
55
    {
56
        $this->schema->dropIfExists((new ReactionCounter())->getTable());
57
    }
58
};
59