Completed
Pull Request — master (#23)
by Armando
10:28
created

UpdateSchema0560To0570   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 133
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 77 2
A down() 0 52 2
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
            \Log::error($e->getMessage ());
85
            return; // Migration may be partly done already...
86
        }
87
    }
88
89
    public function down(): void
90
    {
91
        try {
92
            Schema::table($this->prefix . 'telegram_update', function (Blueprint $table) {
93
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_10');
94
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_9');
95
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_8');
96
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_7');
97
                $table->dropForeign($this->prefix . 'telegram_update_ibfk_6');
98
99
                $table->dropIndex('poll_id');
100
                $table->dropIndex('pre_checkout_query_id');
101
                $table->dropIndex('shipping_query_id');
102
                $table->dropIndex('edited_channel_post_id');
103
                $table->dropIndex('channel_post_id');
104
105
                $table->dropColumn('poll_id');
106
                $table->dropColumn('pre_checkout_query_id');
107
                $table->dropColumn('shipping_query_id');
108
                $table->dropColumn('edited_channel_post_id');
109
                $table->dropColumn('channel_post_id');
110
            });
111
112
            Schema::table($this->prefix . 'message', static function (Blueprint $table) {
113
                $table->dropColumn('successful_payment');
114
                $table->dropColumn('invoice');
115
                $table->dropColumn('poll');
116
                $table->dropColumn('caption_entities');
117
                $table->dropColumn('author_signature');
118
                $table->dropColumn('edit_date');
119
                $table->dropColumn('forward_sender_name');
120
                $table->dropColumn('forward_signature');
121
            });
122
123
            Schema::table($this->prefix . 'chat', static function (Blueprint $table) {
124
                $table->dropColumn('last_name');
125
                $table->dropColumn('first_name');
126
            });
127
128
            Schema::table($this->prefix . 'callback_query', static function (Blueprint $table) {
129
                $table->dropColumn('game_short_name');
130
                $table->dropColumn('chat_instance');
131
            });
132
133
            Schema::dropIfExists($this->prefix . 'poll');
134
            Schema::dropIfExists($this->prefix . 'pre_checkout_query');
135
            Schema::dropIfExists($this->prefix . 'shipping_query');
136
        } catch (Throwable $e) {
137
            \Log::error($e->getMessage ());
138
            return; // Migration may be partly done already...
139
        }
140
    }
141
}
142