Completed
Pull Request — master (#24)
by
unknown
11:40 queued 10s
created

UpdateTelegramUpdateTable::down()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 8.8727
c 0
b 0
f 0
cc 1
nc 1
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\Migrations\Migration;
6
use Illuminate\Database\Schema\Blueprint;
7
8
class UpdateTelegramUpdateTable extends Migration
9
{
10
    public function up ()
11
    {
12
        Schema::table(config('phptelegrambot.database.prefix', '') . 'telegram_update', static function (Blueprint $table) {
13
            $table->bigInteger('channel_post_id')->after('edited_message_id')->unsigned()->nullable()->comment('New incoming channel post of any kind - text, photo, sticker, etc.');
14
            $table->bigInteger('edited_channel_post_id')->after('channel_post_id')->unsigned()->nullable()->comment('New version of a channel post that is known to the bot and was edited');
15
            $table->bigInteger('shipping_query_id')->after('callback_query_id')->unsigned()->nullable()->comment('New incoming shipping query. Only for invoices with flexible price');
16
            $table->bigInteger('pre_checkout_query_id')->after('shipping_query_id')->unsigned()->nullable()->comment('New incoming pre-checkout query. Contains full information about checkout');
17
            $table->bigInteger('poll_id')->after('pre_checkout_query_id')->unsigned()->nullable()->comment('New poll state. Bots receive only updates about polls, which are sent or stopped by the bot');
18
            $table->bigInteger('poll_answer_poll_id')->after('poll_id')->unsigned()->nullable()->comment('A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.');
19
20
            // Add new indexes
21
            $table->dropIndex ('message_id');
22
            $table->index (['message_id'], message_id);
23
            $table->index (['chat_id', 'message_id'], 'chat_message_id');
24
            $table->index (['channel_post_id'], 'channel_post_id');
25
            $table->index (['edited_channel_post_id'], 'edited_channel_post_id');
26
            $table->index (['shipping_query_id'], 'shipping_query_id');
27
            $table->index (['pre_checkout_query_id'], 'pre_checkout_query_id');
28
            $table->index (['poll_id'], 'poll_id');
29
            $table->index (['poll_answer_poll_id'], 'poll_answer_poll_id');
30
            $table->index (['chat_id', 'channel_post_id'], 'chat_id');
31
32
            // Foreign indexes
33
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_5');
34
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_4');
35
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_3');
36
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_2');
37
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_1');
38
39
40
41
42
43
44
45
            $table->foreign (
46
                ['chat_id', 'message_id'],
47
                config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_1'
48
            )
49
                ->references (['chat_id', 'id'])->on (config('phptelegrambot.database.prefix', '') . 'message')
50
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
51
52
            $table->foreign ('edited_message_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_2')
53
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'edited_message')
54
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
55
56
            $table->foreign (['chat_id', 'channel_post_id'], config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_3')
57
                ->references (['chat_id', 'id'])->on (config('phptelegrambot.database.prefix', '') . 'message')
58
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
59
60
            $table->foreign ('edited_channel_post_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_4')
61
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'edited_message')
62
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
63
64
            $table->foreign ('inline_query_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_5')
65
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'inline_query')
66
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
67
68
            $table->foreign ('chosen_inline_result_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_6')
69
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'chosen_inline_result')
70
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
71
72
            $table->foreign ('callback_query_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_7')
73
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'callback_query')
74
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
75
76
            $table->foreign ('shipping_query_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_8')
77
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'shipping_query')
78
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
79
80
            $table->foreign ('pre_checkout_query_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_9')
81
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'pre_checkout_query')
82
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
83
84
            $table->foreign ('poll_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_10')
85
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'poll')
86
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
87
88
            $table->foreign ('poll_answer_poll_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_11')
89
                ->references ('poll_id')->on (config('phptelegrambot.database.prefix', '') . 'poll_answer')
90
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
91
92
        });
93
    }
94
95
    public function down ()
96
    {
97
        Schema::table(config('phptelegrambot.database.prefix', '') . 'telegram_update', static function (Blueprint $table) {
98
            $table->dropColumn ('channel_post_id');
99
            $table->dropColumn ('edited_channel_post_id');
100
            $table->dropColumn ('shipping_query_id');
101
            $table->dropColumn ('pre_checkout_query_id');
102
            $table->dropColumn ('poll_id');
103
            $table->dropColumn ('poll_answer_poll_id');
104
105
            // Rollback old index
106
            $table->dropIndex ('message_id');
107
            $table->index (['chat_id', 'message_id'], 'message_id');
108
109
            // Drop new simple keys
110
            $table->dropIndex ('chat_message_id');
111
            $table->dropIndex ('channel_post_id');
112
            $table->dropIndex ('edited_channel_post_id');
113
            $table->dropIndex ('shipping_query_id');
114
            $table->dropIndex ('pre_checkout_query_id');
115
            $table->dropIndex ('poll_id');
116
            $table->dropIndex ('poll_answer_poll_id');
117
            $table->dropIndex ('chat_id');
118
119
            // Drop new foreign keys
120
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_6');
121
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_7');
122
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_8');
123
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_9');
124
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_10');
125
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_11');
126
127
            // Restore old foreign keys
128
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_1');
129
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_2');
130
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_3');
131
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_4');
132
            $table->dropForeign (config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_5');
133
134
            $table->foreign ('chat_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_1')
135
                ->references ('chat_id')->on (config('phptelegrambot.database.prefix', '') . 'message')
136
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
137
138
            $table->foreign ('inline_query_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_2')
139
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'inline_query')
140
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
141
142
            $table->foreign ('chosen_inline_result_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_3')
143
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'chosen_inline_result')
144
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
145
146
            $table->foreign ('callback_query_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_4')
147
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'callback_query')
148
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
149
150
            $table->foreign ('edited_message_id', config('phptelegrambot.database.prefix', '') . 'telegram_update_ibfk_5')
151
                ->references ('id')->on (config('phptelegrambot.database.prefix', '') . 'edited_message')
152
                ->onUpdate('RESTRICT')->onDelete('RESTRICT');
153
        });
154
    }
155
}
156