|
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 UpdateSchemaFixes extends Migration |
|
11
|
|
|
{ |
|
12
|
|
|
public function up(): void |
|
13
|
|
|
{ |
|
14
|
|
|
try { |
|
15
|
|
|
Schema::table($this->prefix . 'callback_query', function (Blueprint $table) { |
|
16
|
|
|
$table->dropForeign('callback_query_ibfk_2'); |
|
17
|
|
|
$table->foreign(['chat_id', 'message_id'], 'callback_query_ibfk_2')->references(['chat_id', 'id'])->on($this->prefix . 'message')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
|
18
|
|
|
}); |
|
19
|
|
|
|
|
20
|
|
|
Schema::table($this->prefix . 'edited_message', function (Blueprint $table) { |
|
21
|
|
|
$table->dropForeign('edited_message_ibfk_2'); |
|
22
|
|
|
$table->foreign(['chat_id', 'message_id'], 'edited_message_ibfk_2')->references(['chat_id', 'id'])->on($this->prefix . 'message')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
|
23
|
|
|
}); |
|
24
|
|
|
|
|
25
|
|
|
Schema::table($this->prefix . 'message', function (Blueprint $table) { |
|
26
|
|
|
$table->dropForeign('message_ibfk_5'); |
|
27
|
|
|
$table->dropForeign('message_ibfk_6'); |
|
28
|
|
|
$table->foreign(['reply_to_chat', 'reply_to_message'], 'message_ibfk_5')->references(['chat_id', 'id'])->on($this->prefix . 'message')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
|
29
|
|
|
}); |
|
30
|
|
|
} catch (Throwable $e) { |
|
31
|
|
|
Log::error($e->getMessage()); |
|
32
|
|
|
return; // Migration may be partly done already... |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function down(): void |
|
37
|
|
|
{ |
|
38
|
|
|
try { |
|
39
|
|
|
Schema::table($this->prefix . 'callback_query', function (Blueprint $table) { |
|
40
|
|
|
$table->dropForeign('callback_query_ibfk_2'); |
|
41
|
|
|
$table->foreign('chat_id', 'callback_query_ibfk_2')->references('chat_id')->on($this->prefix . 'message')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
Schema::table($this->prefix . 'edited_message', function (Blueprint $table) { |
|
45
|
|
|
$table->dropForeign('edited_message_ibfk_2'); |
|
46
|
|
|
$table->foreign('chat_id', 'edited_message_ibfk_2')->references('chat_id')->on($this->prefix . 'message')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
Schema::table($this->prefix . 'message', function (Blueprint $table) { |
|
50
|
|
|
$table->dropForeign('message_ibfk_5'); |
|
51
|
|
|
$table->foreign('reply_to_chat', 'message_ibfk_5')->references('chat_id')->on($this->prefix . 'message')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
|
52
|
|
|
$table->foreign('forward_from', 'message_ibfk_6')->references('id')->on($this->prefix . 'user')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
|
53
|
|
|
}); |
|
54
|
|
|
} catch (Throwable $e) { |
|
55
|
|
|
Log::error($e->getMessage()); |
|
56
|
|
|
return; // Migration may be partly done already... |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|