Passed
Push — master ( ab2678...bf154d )
by webdevetc
14:17
created

CreateBlogEtcPostsTable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 46
dl 0
loc 75
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 6 1
A up() 0 58 1
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
/**
8
 * Class CreateBlogEtcPostsTable.
9
 */
10
class CreateBlogEtcPostsTable extends Migration
11
{
12
    /**
13
     * Initial DB table setup for blog etc package.
14
     */
15
    public function up(): void
16
    {
17
        Schema::create('blog_etc_posts', static function (Blueprint $table) {
18
            $table->increments('id');
19
20
            $table->string('slug')->unique();
21
            $table->unsignedInteger('user_id')->index()->nullable();
22
            $table->string('title')->nullable()->default('New blog post');
23
            $table->string('subtitle')->nullable()->default('');
24
            $table->text('meta_desc')->nullable();
25
            $table->mediumText('post_body')->nullable();
26
            $table->string('use_view_file')
27
                ->nullable()
28
                ->comment('If not null, this should refer to a blade file in /views/');
29
            $table->dateTime('posted_at')->index()->nullable()
30
                ->comment('Public posted at time, if this is in future then it wont appear yet');
31
            $table->boolean('is_published')->default(true);
32
            $table->string('image_large')->nullable();
33
            $table->string('image_medium')->nullable();
34
            $table->string('image_thumbnail')->nullable();
35
36
            $table->timestamps();
37
        });
38
39
        Schema::create('blog_etc_categories', static function (Blueprint $table) {
40
            $table->increments('id');
41
42
            $table->string('category_name')->nullable();
43
            $table->string('slug')->unique();
44
            $table->mediumText('category_description')->nullable();
45
            $table->unsignedInteger('created_by')->nullable()->index()->comment('user id');
46
47
            $table->timestamps();
48
        });
49
50
        // linking table:
51
        Schema::create('blog_etc_post_categories', static function (Blueprint $table) {
52
            $table->increments('id');
53
54
            $table->unsignedInteger('blog_etc_post_id')->index();
55
            $table->foreign('blog_etc_post_id')->references('id')->on('blog_etc_posts')->onDelete('cascade');
56
            $table->unsignedInteger('blog_etc_category_id')->index();
57
58
            $table->foreign('blog_etc_category_id')->references('id')->on('blog_etc_categories')->onDelete('cascade');
59
        });
60
61
        Schema::create('blog_etc_comments', static function (Blueprint $table) {
62
            $table->increments('id');
63
64
            $table->unsignedInteger('blog_etc_post_id')->index();
65
            $table->foreign('blog_etc_post_id')->references('id')->on('blog_etc_posts')->onDelete('cascade');
66
            $table->unsignedInteger('user_id')->nullable()->index()->comment('if user was logged in');
67
            $table->string('ip')->nullable()->comment('if enabled in the config file');
68
            $table->string('author_name')->nullable()->comment('if not logged in');
69
            $table->text('comment')->comment('the comment body');
70
            $table->boolean('approved')->default(true);
71
72
            $table->timestamps();
73
        });
74
    }
75
76
    /**
77
     * Reverse the migrations.
78
     */
79
    public function down(): void
80
    {
81
        Schema::dropIfExists('blog_etc_comments');
82
        Schema::dropIfExists('blog_etc_post_categories');
83
        Schema::dropIfExists('blog_etc_categories');
84
        Schema::dropIfExists('blog_etc_posts');
85
    }
86
}
87