Completed
Push — master ( b08809...5efe48 )
by Abdelrahman
01:22 queued 10s
created

CreateFormsTable::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Support\Facades\Schema;
6
use Illuminate\Database\Schema\Blueprint;
7
use Illuminate\Database\Migrations\Migration;
8
9
class CreateFormsTable extends Migration
10
{
11
    /**
12
     * Run the migrations.
13
     *
14
     * @return void
15
     */
16
    public function up()
17
    {
18
        Schema::create(config('rinvex.forms.tables.forms'), function (Blueprint $table) {
19
            // Columns
20
            $table->increments('id');
21
            $table->nullableMorphs('entity');
22
            $table->string('slug');
23
            $table->{$this->jsonable()}('name');
24
            $table->{$this->jsonable()}('description')->nullable();
25
            $table->{$this->jsonable()}('content');
26
            $table->{$this->jsonable()}('actions')->nullable();
27
            $table->{$this->jsonable()}('submission')->nullable();
28
            $table->boolean('is_active')->default(false);
29
            $table->boolean('is_public')->default(false);
30
            $table->timestamps();
31
            $table->softDeletes();
32
33
            // Indexes
34
            $table->unique('slug');
35
        });
36
    }
37
38
    /**
39
     * Reverse the migrations.
40
     *
41
     * @return void
42
     */
43
    public function down()
44
    {
45
        Schema::dropIfExists(config('rinvex.forms.tables.forms'));
46
    }
47
48
    /**
49
     * Get jsonable column data type.
50
     *
51
     * @return string
52
     */
53
    protected function jsonable(): string
54
    {
55
        $driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
56
        $dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
57
        $isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');
58
59
        return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
60
    }
61
}
62