Passed
Push — master ( fde606...0af3c0 )
by Armando
08:21
created

UpdateSchema0570To0580::down()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 18
rs 9.8333
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 UpdateSchema0570To0580 extends Migration
11
{
12
    public function up(): void
13
    {
14
        try {
15
            Schema::dropIfExists($this->prefix . 'botan_shortener');
16
            Schema::table($this->prefix . 'message', static function (Blueprint $table) {
17
                $table->text('reply_markup')->nullable()->comment('Inline keyboard attached to the message')->after('passport_data');
18
            });
19
        } catch (Throwable $e) {
20
            Log::error($e->getMessage());
21
            return; // Migration may be partly done already...
22
        }
23
    }
24
25
    public function down(): void
26
    {
27
        try {
28
            Schema::create('botan_shortener', function (Blueprint $table) {
29
                $table->bigInteger('id', true)->unsigned()->comment('Unique identifier for this entry');
30
                $table->bigInteger('user_id')->nullable()->index('user_id')->comment('Unique user identifier');
31
                $table->text('url')->comment('Original URL');
32
                $table->char('short_url')->default('')->comment('Shortened URL');
33
                $table->timestamp('created_at')->nullable()->comment('Entry date creation');
34
                $table->foreign('user_id', 'botan_shortener_ibfk_1')->references('id')->on($this->prefix . 'user')->onUpdate('RESTRICT')->onDelete('RESTRICT');
35
            });
36
37
            Schema::table($this->prefix . 'message', static function (Blueprint $table) {
38
                $table->dropColumn('reply_markup');
39
            });
40
        } catch (Throwable $e) {
41
            Log::error($e->getMessage());
42
            return; // Migration may be partly done already...
43
        }
44
    }
45
}
46