Completed
Pull Request — develop (#16)
by
unknown
10:04
created

CreatePagesTable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonable() 0 8 3
A up() 0 26 1
A down() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
use Illuminate\Support\Facades\Schema;
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Database\Migrations\Migration;
7
8
class CreatePagesTable extends Migration
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up(): void
16
    {
17
        Schema::create(config('rinvex.pages.tables.pages'), function (Blueprint $table) {
18
            // Columns
19
            $table->increments('id');
20
            $table->string('uri');
21
            $table->string('slug');
22
            $table->string('route');
23
            $table->string('domain')->nullable();
24
            $table->string('middleware')->nullable();
25
            $table->{$this->jsonable()}('title');
26
            $table->{$this->jsonable()}('subtitle')->nullable();
27
            $table->{$this->jsonable()}('excerpt')->nullable();
28
            $table->{$this->jsonable()}('content')->nullable();
29
            $table->string('view');
30
            $table->boolean('is_active')->default(true);
31
            $table->mediumInteger('sort_order')->unsigned()->default(0);
32
            $table->timestamps();
33
            $table->softDeletes();
34
35
            // Indexes
36
            $table->unique(['domain', 'uri']);
37
            $table->unique(['domain', 'slug']);
38
            $table->unique(['domain', 'route']);
39
        });
40
    }
41
42
    /**
43
     * Reverse the migrations.
44
     *
45
     * @return void
46
     */
47
    public function down(): void
48
    {
49
        Schema::dropIfExists(config('rinvex.pages.tables.pages'));
50
    }
51
52
    /**
53
     * Get jsonable column data type.
54
     *
55
     * @return string
56
     */
57
    protected function jsonable(): string
58
    {
59
        $driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
60
        $dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
61
        $isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');
62
63
        return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
64
    }
65
}
66