Completed
Push — develop ( 7ec5c3...0ba76f )
by Abdelrahman
01:08
created

CreateTenantsTable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 28 1
A down() 0 4 1
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 CreateTenantsTable extends Migration
10
{
11
    /**
12
     * Run the migrations.
13
     *
14
     * @return void
15
     */
16
    public function up(): void
17
    {
18
        Schema::create(config('rinvex.tenants.tables.tenants'), function (Blueprint $table) {
19
            // Columns
20
            $table->increments('id');
21
            $table->string('slug');
22
            $table->{$this->jsonable()}('name');
23
            $table->{$this->jsonable()}('description')->nullable();
24
            $table->string('email');
25
            $table->string('website')->nullable();
26
            $table->string('phone')->nullable();
27
            $table->string('language_code', 2);
28
            $table->string('country_code', 2);
29
            $table->string('state')->nullable();
30
            $table->string('city')->nullable();
31
            $table->string('address')->nullable();
32
            $table->string('postal_code')->nullable();
33
            $table->date('launch_date')->nullable();
34
            $table->string('timezone')->nullable();
35
            $table->string('currency')->nullable();
36
            $table->boolean('is_active')->default(true);
37
            $table->timestamps();
38
            $table->softDeletes();
39
40
            // Indexes
41
            $table->unique('slug');
42
        });
43
    }
44
45
    /**
46
     * Reverse the migrations.
47
     *
48
     * @return void
49
     */
50
    public function down(): void
51
    {
52
        Schema::dropIfExists(config('rinvex.tenants.tables.tenants'));
53
    }
54
55
    /**
56
     * Get jsonable column data type.
57
     *
58
     * @return string
59
     */
60
    protected function jsonable(): string
61
    {
62
        $driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
63
        $dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
64
        $isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');
65
66
        return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
67
    }
68
}
69