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

UpdateSchema0620To0630::down()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 25
rs 9.7
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 UpdateSchema0620To0630 extends Migration
11
{
12
    public function up(): void
13
    {
14
        try {
15
            Schema::table($this->prefix . 'poll', static function (Blueprint $table) {
16
                $table->char('explanation', 255)->nullable()->comment('Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters')->after('correct_option_id');
17
                $table->text('explanation_entities')->nullable()->comment('Special entities like usernames, URLs, bot commands, etc. that appear in the explanation')->after('explanation');
18
                $table->integer('open_period')->unsigned()->nullable()->comment('Amount of time in seconds the poll will be active after creation')->after('explanation_entities');
19
                $table->timestamp('close_date')->nullable()->comment('Point in time (Unix timestamp) when the poll will be automatically closed')->after('open_period');
20
            });
21
22
            Schema::table($this->prefix . 'poll_answer', static function (Blueprint $table) {
23
                $table->dropPrimary();
24
                $table->primary(['poll_id', 'user_id']);
25
            });
26
27
            Schema::table($this->prefix . 'message', function (Blueprint $table) {
28
                $table->dropForeign('message_ibfk_6');
29
                $table->dropIndex('message_ibfk_6');
30
31
                $table->bigInteger('via_bot')->nullable()->comment('Optional. Bot through which the message was sent')->after('reply_to_message');
32
                $table->index('via_bot');
33
                $table->foreign('via_bot', 'message_ibfk_9')->references('id')->on($this->prefix . 'user')->onUpdate('RESTRICT')->onDelete('RESTRICT');
34
            });
35
        } catch (Throwable $e) {
36
            Log::error($e->getMessage());
37
            return; // Migration may be partly done already...
38
        }
39
    }
40
41
    public function down(): void
42
    {
43
        try {
44
            Schema::table($this->prefix . 'poll', static function (Blueprint $table) {
45
                $table->dropColumn('explanation');
46
                $table->dropColumn('explanation_entities');
47
                $table->dropColumn('open_period');
48
                $table->dropColumn('close_date');
49
            });
50
51
            Schema::table($this->prefix . 'poll_answer', static function (Blueprint $table) {
52
                $table->dropPrimary();
53
                $table->primary('poll_id');
54
            });
55
56
            Schema::table($this->prefix . 'message', function (Blueprint $table) {
57
                $table->dropForeign('message_ibfk_9');
58
                $table->dropIndex('via_bot');
59
                $table->dropColumn('via_bot');
60
61
                $table->foreign('forward_from', 'message_ibfk_6')->references('id')->on($this->prefix . 'user')->onUpdate('RESTRICT')->onDelete('RESTRICT');
62
            });
63
        } catch (Throwable $e) {
64
            Log::error($e->getMessage());
65
            return; // Migration may be partly done already...
66
        }
67
    }
68
}
69