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

CreateTransactionsTable::table()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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