1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
6
|
|
|
use Illuminate\Database\Schema\Blueprint; |
7
|
|
|
use Illuminate\Support\Facades\Schema; |
8
|
|
|
|
9
|
|
|
class AddForeignKeysToMessageTable extends Migration |
10
|
|
|
{ |
11
|
|
|
public function up(): void |
12
|
|
|
{ |
13
|
|
|
Schema::table('message', static function (Blueprint $table) { |
14
|
|
|
$table->foreign('user_id', 'message_ibfk_1')->references('id')->on('user')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
15
|
|
|
$table->foreign('chat_id', 'message_ibfk_2')->references('id')->on('chat')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
16
|
|
|
$table->foreign('forward_from', 'message_ibfk_3')->references('id')->on('user')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
17
|
|
|
$table->foreign('forward_from_chat', 'message_ibfk_4')->references('id')->on('chat')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
18
|
|
|
$table->foreign('reply_to_chat', 'message_ibfk_5')->references('chat_id')->on('message')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
19
|
|
|
$table->foreign('forward_from', 'message_ibfk_6')->references('id')->on('user')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
20
|
|
|
$table->foreign('left_chat_member', 'message_ibfk_7')->references('id')->on('user')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
21
|
|
|
}); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function down(): void |
25
|
|
|
{ |
26
|
|
|
Schema::table('message', static function (Blueprint $table) { |
27
|
|
|
$table->dropForeign('message_ibfk_1'); |
28
|
|
|
$table->dropForeign('message_ibfk_2'); |
29
|
|
|
$table->dropForeign('message_ibfk_3'); |
30
|
|
|
$table->dropForeign('message_ibfk_4'); |
31
|
|
|
$table->dropForeign('message_ibfk_5'); |
32
|
|
|
$table->dropForeign('message_ibfk_6'); |
33
|
|
|
$table->dropForeign('message_ibfk_7'); |
34
|
|
|
}); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|