-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path2023_11_06_222300_create_comments_table.php
executable file
·49 lines (43 loc) · 1.32 KB
/
2023_11_06_222300_create_comments_table.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('post_id')->nullable();
$table->unsignedBigInteger('user_id')->nullable();
$table->unsignedBigInteger('parent_id')->nullable();
$table->text('content');
$table->boolean('approved')->default(true);
$table->softDeletes();
$table->timestamps();
$table->index(['approved', 'post_id']);
$table->index('post_id');
$table->index('parent_id');
$table->foreign('post_id')
->references('id')
->on('posts')
->onUpdate('cascade')
->onDelete('cascade');
$table->foreign('user_id')
->references('id')
->on('users')
->onUpdate('cascade')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('comments');
}
};