Skip to content

Commit 954f32e

Browse files
authored
Merge pull request #10 from DemianShtepa/fix/add-cascade-delete
Add cascade delete
2 parents 21f831a + 28ea626 commit 954f32e

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('posts', function (Blueprint $table) {
15+
$table->foreignIdFor(config('filamentblog.user.model'), config('filamentblog.user.foreign_key'))
16+
->change()
17+
->constrained()
18+
->cascadeOnDelete();
19+
});
20+
21+
Schema::table('category_post', function (Blueprint $table) {
22+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
23+
->change()
24+
->constrained()
25+
->cascadeOnDelete();
26+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Category::class)
27+
->change()
28+
->constrained()
29+
->cascadeOnDelete();
30+
});
31+
32+
Schema::table('seo_details', function (Blueprint $table) {
33+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
34+
->change()
35+
->constrained()
36+
->cascadeOnDelete();
37+
});
38+
39+
Schema::table('comments', function (Blueprint $table) {
40+
$table->foreignIdFor(config('filamentblog.user.model'), config('filamentblog.user.foreign_key'))
41+
->change()
42+
->constrained()
43+
->cascadeOnDelete();
44+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
45+
->change()
46+
->constrained()
47+
->cascadeOnDelete();
48+
});
49+
50+
Schema::table('post_tag', function (Blueprint $table) {
51+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
52+
->change()
53+
->constrained()
54+
->cascadeOnDelete();
55+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Tag::class)
56+
->change()
57+
->constrained()
58+
->cascadeOnDelete();
59+
});
60+
}
61+
62+
/**
63+
* Reverse the migrations.
64+
*/
65+
public function down(): void
66+
{
67+
Schema::table('posts', function (Blueprint $table) {
68+
$table->foreignIdFor(config('filamentblog.user.model'), config('filamentblog.user.foreign_key'))
69+
->change();
70+
});
71+
72+
Schema::table('category_post', function (Blueprint $table) {
73+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
74+
->change();
75+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Category::class)
76+
->change();
77+
});
78+
79+
Schema::table('seo_details', function (Blueprint $table) {
80+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
81+
->change();
82+
});
83+
84+
Schema::table('comments', function (Blueprint $table) {
85+
$table->foreignIdFor(config('filamentblog.user.model'), config('filamentblog.user.foreign_key'))
86+
->change();
87+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
88+
->change();
89+
});
90+
91+
Schema::table('post_tag', function (Blueprint $table) {
92+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Post::class)
93+
->change();
94+
$table->foreignIdFor(Firefly\FilamentBlog\Models\Tag::class)
95+
->change();
96+
});
97+
}
98+
};

0 commit comments

Comments
 (0)