Completed
Pull Request — master (#23)
by Armando
13:41
created

UpdateSchema0560To0570::down()   A

Complexity

Conditions 2
Paths 8

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.069
c 0
b 0
f 0
cc 2
nc 8
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Support\Facades\Schema;
7
use PhpTelegramBot\Laravel\Migration;
8
9
class UpdateSchema0560To0570 extends Migration
10
{
11
    public function up(): void
12
    {
13
        try {
14
            Schema::create($this->prefix . 'shipping_query', function (Blueprint $table) {
15
                $table->bigInteger('id')->unsigned()->primary()->comment('Unique query identifier');
16
                $table->bigInteger('user_id')->index('user_id')->comment('User who sent the query');
17
                $table->char('invoice_payload', 255)->default('')->comment('Bot specified invoice payload');
18
                $table->char('shipping_address', 255)->default('')->comment('User specified shipping address');
19
                $table->dateTime('created_at')->nullable()->comment('Entry date creation');
20
                $table->foreign('user_id', $this->prefix . 'shipping_query_ibfk_1')->references('id')->on($this->prefix . 'user')->onUpdate('RESTRICT')->onDelete('RESTRICT');
21
            });
22
23
            Schema::create($this->prefix . 'pre_checkout_query', function (Blueprint $table) {
24
                $table->bigInteger('id')->unsigned()->primary()->comment('Unique query identifier');
25
                $table->bigInteger('user_id')->index('user_id')->comment('User who sent the query');
26
                $table->char('currency', 3)->comment('Three-letter ISO 4217 currency code');
27
                $table->bigInteger('total_amount')->comment('Total price in the smallest units of the currency');
28
                $table->char('invoice_payload', 255)->default('')->comment('Bot specified invoice payload');
29
                $table->char('shipping_option_id', 255)->comment('Identifier of the shipping option chosen by the user');
30
                $table->text('order_info')->comment('Order info provided by the user');
31
                $table->dateTime('created_at')->nullable()->comment('Entry date creation');
32
                $table->foreign('user_id', $this->prefix . 'pre_checkout_query_ibfk_1')->references('id')->on($this->prefix . 'user')->onUpdate('RESTRICT')->onDelete('RESTRICT');
33
            });
34
35
            Schema::create($this->prefix . 'poll', static function (Blueprint $table) {
36
                $table->bigInteger('id')->unsigned()->primary()->comment('Unique poll identifier');
37
                $table->char('question', 255)->comment('Poll question');
38
                $table->text('options')->comment('List of poll options');
39
                $table->tinyInteger('is_closed')->default(0)->comment('True, if the poll is closed');
40
                $table->dateTime('created_at')->nullable()->comment('Entry date creation');
41
            });
42
43
            Schema::table($this->prefix . 'callback_query', static function (Blueprint $table) {
44
                $table->char('chat_instance', 255)->default('')->comment('Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent')->after('inline_message_id');
45
                $table->char('game_short_name', 255)->default('')->comment('Short name of a Game to be returned, serves as the unique identifier for the game')->after('data');
46
            });
47
48
            Schema::table($this->prefix . 'chat', static function (Blueprint $table) {
49
                $table->char('first_name', 255)->nullable()->comment('First name of the other party in a private chat')->after('username');
50
                $table->char('last_name', 255)->nullable()->comment('Last name of the other party in a private chat')->after('first_name');
51
            });
52
53
            Schema::table($this->prefix . 'message', static function (Blueprint $table) {
54
                $table->text('forward_signature')->nullable()->default(null)->comment('For messages forwarded from channels, signature of the post author if present')->after('forward_from_message_id');
55
                $table->text('forward_sender_name')->nullable()->default(null)->comment('Sender\'s name for messages forwarded from users who disallow adding a link to their account in forwarded messages')->after('forward_signature');
56
                $table->unsignedBigInteger('edit_date')->default(null)->comment('Date the message was last edited in Unix time')->after('reply_to_message');
57
                $table->text('author_signature')->comment('Signature of the post author for messages in channels')->after('media_group_id');
58
                $table->text('caption_entities')->comment('For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption')->after('entities');
59
                $table->text('poll')->comment('Poll object. Message is a native poll, information about the poll')->after('venue');
60
                $table->text('invoice')->nullable()->comment('Message is an invoice for a payment, information about the invoice')->after('pinned_message');
61
                $table->text('successful_payment')->nullable()->comment('Message is a service message about a successful payment, information about the payment')->after('invoice');
62
            });
63
64
            Schema::table($this->prefix . 'telegram_update', function (Blueprint $table) {
65
                $table->bigInteger('channel_post_id')->unsigned()->nullable()->comment('New incoming channel post of any kind - text, photo, sticker, etc.');
66
                $table->bigInteger('edited_channel_post_id')->unsigned()->nullable()->comment('New version of a channel post that is known to the bot and was edited');
67
                $table->bigInteger('shipping_query_id')->unsigned()->nullable()->comment('New incoming shipping query. Only for invoices with flexible price');
68
                $table->bigInteger('pre_checkout_query_id')->unsigned()->nullable()->comment('New incoming pre-checkout query. Contains full information about checkout');
69
                $table->bigInteger('poll_id')->unsigned()->nullable()->comment('New poll state. Bots receive only updates about polls, which are sent or stopped by the bot');
70
71
                $table->index('channel_post_id', 'channel_post_id');
72
                $table->index('edited_channel_post_id', 'edited_channel_post_id');
73
                $table->index('shipping_query_id', 'shipping_query_id');
74
                $table->index('pre_checkout_query_id', 'pre_checkout_query_id');
75
                $table->index('poll_id', 'poll_id');
76
77
                $table->foreign(['chat_id', 'channel_post_id'], $this->prefix . 'telegram_update_ibfk_6')->references(['chat_id', 'id'])->on($this->prefix . 'message');
78
                $table->foreign('edited_channel_post_id', $this->prefix . 'telegram_update_ibfk_7')->references('id')->on($this->prefix . 'edited_message');
79
                $table->foreign('shipping_query_id', $this->prefix . 'telegram_update_ibfk_8')->references('id')->on($this->prefix . 'shipping_query');
80
                $table->foreign('pre_checkout_query_id', $this->prefix . 'telegram_update_ibfk_9')->references('id')->on($this->prefix . 'pre_checkout_query');
81
                $table->foreign('poll_id', $this->prefix . 'telegram_update_ibfk_10')->references('id')->on($this->prefix . 'poll');
82
            });
83
        } catch (Throwable $e) {
84
            return; // Migration may be partly done already...
85
        }
86
    }
87
88
    public function down(): void
89
    {
90
        try {
91
            Schema::table($this->prefix . 'telegram_update', function (Blueprint $table) {
92
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_10');
93
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_9');
94
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_8');
95
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_7');
96
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_6');
97
98
                $table->dropIndex('poll_id');
99
                $table->dropIndex('pre_checkout_query_id');
100
                $table->dropIndex('shipping_query_id');
101
                $table->dropIndex('edited_channel_post_id');
102
                $table->dropIndex('channel_post_id');
103
104
                $table->dropColumn('poll_id');
105
                $table->dropColumn('pre_checkout_query_id');
106
                $table->dropColumn('shipping_query_id');
107
                $table->dropColumn('edited_channel_post_id');
108
                $table->dropColumn('channel_post_id');
109
            });
110
111
            Schema::table($this->prefix . 'message', static function (Blueprint $table) {
112
                $table->dropColumn('successful_payment');
113
                $table->dropColumn('invoice');
114
                $table->dropColumn('poll');
115
                $table->dropColumn('caption_entities');
116
                $table->dropColumn('author_signature');
117
                $table->dropColumn('edit_date');
118
                $table->dropColumn('forward_sender_name');
119
                $table->dropColumn('forward_signature');
120
            });
121
122
            Schema::table($this->prefix . 'chat', static function (Blueprint $table) {
123
                $table->dropColumn('last_name');
124
                $table->dropColumn('first_name');
125
            });
126
127
            Schema::table($this->prefix . 'callback_query', static function (Blueprint $table) {
128
                $table->dropColumn('game_short_name');
129
                $table->dropColumn('chat_instance');
130
            });
131
132
            Schema::dropIfExists($this->prefix . 'poll');
133
            Schema::dropIfExists($this->prefix . 'pre_checkout_query');
134
            Schema::dropIfExists($this->prefix . 'shipping_query');
135
        } catch (Throwable $e) {
136
            return; // Migration may be partly done already...
137
        }
138
    }
139
}
140