Passed
Push — master ( 762883...d275c6 )
by Бабичев
01:38
created

CreateTransactionsTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 3
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
use Bavix\Wallet\Models\Transaction;
7
8
class CreateTransactionsTable extends Migration
9
{
10
11
    /**
12
     * @return string
13
     */
14
    protected function table(): string
15
    {
16
        return (new Transaction())->getTable();
17
    }
18
19
    /**
20
     * @return void
21
     */
22
    public function up(): void
23
    {
24
        Schema::create($this->table(), function(Blueprint $table) {
25
            $table->increments('id');
26
            $table->morphs('payable');
27
            $table->enum('type', ['deposit', 'withdraw'])->index();
28
            $table->bigInteger('amount');
29
            $table->boolean('confirmed');
30
            $table->json('meta')->nullable();
31
            $table->uuid('uuid')->unique();
32
            $table->timestamps();
33
34
            $table->index(['payable_type', 'payable_id', 'type'], 'payable_type_ind');
35
            $table->index(['payable_type', 'payable_id', 'confirmed'], 'payable_confirmed_ind');
36
            $table->index(['payable_type', 'payable_id', 'type', 'confirmed'], 'payable_type_confirmed_ind');
37
        });
38
    }
39
40
    /**
41
     * @return void
42
     */
43
    public function down(): void
44
    {
45
        Schema::drop($this->table());
46
    }
47
48
}
49