Test Failed
Push — master ( 8058df...bae25b )
by Nur
10:24 queued 27s
created

CreateLikeableTables::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
/**
8
 * Class CreateLikeableTables
9
 */
10
class CreateLikeableTables extends Migration
11
{
12
    /**
13
     * Run the migrations.
14
     *
15
     * @return void
16
     */
17
    public function up()
18
	{
19
		Schema::create('likes', function(Blueprint $table) {
20
            $table->id();
21
			$table->morphs('likeable');
22
			$table->unsignedBigInteger('user_id')->index();
23
            $table->enum('type_id', [
24
                'like',
25
                'dislike',
26
            ])->default('like');
27
			$table->timestamps();
28
29
            $table->unique([
30
                'likeable_id',
31
                'likeable_type',
32
                'user_id',
33
            ], 'like_user_unique');
34
35
		});
36
37
		Schema::create('like_counters', function(Blueprint $table) {
38
			$table->id();
39
			$table->morphs('likeable');
40
            $table->enum('type_id', [
41
                'like',
42
                'dislike',
43
            ])->default('like');
44
			$table->unsignedBigInteger('count')->default(0);
45
			$table->timestamps();
46
47
            $table->unique([
48
                'likeable_id',
49
                'likeable_type',
50
                'type_id',
51
            ], 'like_counter_unique');
52
		});
53
54
	}
55
56
    /**
57
     * Reverse the migrations.
58
     *
59
     * @return void
60
     */
61
    public function down()
62
	{
63
		Schema::drop('likes');
64
		Schema::drop('like_counters');
65
	}
66
}
67