Completed
Push — master ( e4d660...050514 )
by Abdelrahman
02:52 queued 01:47
created

2017_05_03_204335_create_plan_features_table.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Database\Migrations\Migration;
7
8
class CreatePlanFeaturesTable extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up(): void
16
    {
17
        Schema::create(config('rinvex.subscriptions.tables.plan_features'), function (Blueprint $table) {
18
            // Columns
19
            $table->increments('id');
20
            $table->integer('plan_id')->unsigned();
21
            $table->string('slug');
22
            $table->{$this->jsonable()}('name');
23
            $table->{$this->jsonable()}('description')->nullable();
24
            $table->string('value');
25
            $table->smallInteger('resettable_period')->unsigned()->default(0);
26
            $table->string('resettable_interval')->default('month');
27
            $table->mediumInteger('sort_order')->unsigned()->default(0);
28
            $table->timestamps();
29
            $table->softDeletes();
30
31
            // Indexes
32
            $table->unique(['plan_id', 'slug']);
33
            $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans'))
34
                  ->onDelete('cascade')->onUpdate('cascade');
35
        });
36
    }
37
38
    /**
39
     * Reverse the migrations.
40
     *
41
     * @return void
42
     */
43
    public function down(): void
44
    {
45
        Schema::dropIfExists(config('rinvex.subscriptions.tables.plan_features'));
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