Passed
Pull Request — master (#9)
by Бабичев
02:39
created

UpdateTransfersTable::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 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
use Illuminate\Support\Facades\DB;
4
use Illuminate\Support\Facades\Schema;
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Database\SQLiteConnection;
7
use Illuminate\Database\Migrations\Migration;
8
use Bavix\Wallet\Models\Transfer;
9
10
class UpdateTransfersTable extends Migration
11
{
12
13
    /**
14
     * @return string
15
     */
16
    protected function table(): string
17
    {
18
        return (new Transfer())->getTable();
19
    }
20
21
    /**
22
     * @return void
23
     */
24
    public function up(): void
25
    {
26
        Schema::table($this->table(), function(Blueprint $table) {
27
            $table->boolean('refund')
28
                ->after('withdraw_id')
29
                ->default(0);
30
31
            $table->index(['from_type', 'from_id', 'to_type', 'to_id', 'refund'], 'from_to_refund_ind');
32
            $table->index(['from_type', 'from_id', 'refund'], 'from_refund_ind');
33
            $table->index(['to_type', 'to_id', 'refund'], 'to_refund_ind');
34
        });
35
    }
36
37
    /**
38
     * @return void
39
     */
40
    public function down(): void
41
    {
42
        Schema::table($this->table(), function(Blueprint $table) {
43
            if (!(DB::connection() instanceof SQLiteConnection)) {
44
                $table->dropIndex('from_to_refund_ind');
45
                $table->dropIndex('from_refund_ind');
46
                $table->dropIndex('to_refund_ind');
47
            }
48
49
            $table->dropColumn('refund');
50
        });
51
    }
52
53
}
54