UpdateSchema0600To0610::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Support\Facades\Log;
7
use Illuminate\Support\Facades\Schema;
8
use PhpTelegramBot\Laravel\Migration;
9
10
class UpdateSchema0600To0610 extends Migration
11
{
12
    public function up(): void
13
    {
14
        Schema::disableForeignKeyConstraints();
15
16
        try {
17
            Schema::table($this->prefix . 'telegram_update', static function (Blueprint $table) {
18
                $table->dropIndex('message_id');
19
                $table->index('message_id', 'message_id');
20
                $table->index(['chat_id', 'message_id'], 'chat_message_id');
21
            });
22
        } catch (Throwable $e) {
23
            Log::error($e->getMessage());
24
            return; // Migration may be partly done already...
25
        }
26
27
        Schema::enableForeignKeyConstraints();
28
    }
29
30
    public function down(): void
31
    {
32
        Schema::disableForeignKeyConstraints();
33
34
        try {
35
            Schema::table($this->prefix . 'telegram_update', static function (Blueprint $table) {
36
                $table->dropIndex('chat_message_id');
37
                $table->dropIndex('message_id');
38
                $table->index('message_id', 'message_id');
39
            });
40
        } catch (Throwable $e) {
41
            Log::error($e->getMessage());
42
            return; // Migration may be partly done already...
43
        }
44
45
        Schema::enableForeignKeyConstraints();
46
    }
47
}
48