|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
6
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
7
|
|
|
|
|
8
|
|
|
class CreatePlansTable extends Migration |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Run the migrations. |
|
12
|
|
|
* |
|
13
|
|
|
* @return void |
|
14
|
|
|
*/ |
|
15
|
|
|
public function up(): void |
|
16
|
|
|
{ |
|
17
|
|
|
Schema::create(config('rinvex.subscriptions.tables.plans'), function (Blueprint $table) { |
|
18
|
|
|
// Columns |
|
19
|
|
|
$table->increments('id'); |
|
20
|
|
|
$table->string('slug'); |
|
21
|
|
|
$table->{$this->jsonable()}('name'); |
|
22
|
|
|
$table->{$this->jsonable()}('description')->nullable(); |
|
23
|
|
|
$table->boolean('is_active')->default(true); |
|
24
|
|
|
$table->decimal('price')->default('0.00'); |
|
25
|
|
|
$table->decimal('signup_fee')->default('0.00'); |
|
26
|
|
|
$table->string('currency', 3); |
|
27
|
|
|
$table->smallInteger('trial_period')->unsigned()->default(0); |
|
28
|
|
|
$table->string('trial_interval')->default('day'); |
|
29
|
|
|
$table->smallInteger('invoice_period')->unsigned()->default(0); |
|
30
|
|
|
$table->string('invoice_interval')->default('month'); |
|
31
|
|
|
$table->smallInteger('grace_period')->unsigned()->default(0); |
|
32
|
|
|
$table->string('grace_interval')->default('day'); |
|
33
|
|
|
$table->tinyInteger('prorate_day')->unsigned()->nullable(); |
|
34
|
|
|
$table->tinyInteger('prorate_period')->unsigned()->nullable(); |
|
35
|
|
|
$table->tinyInteger('prorate_extend_due')->unsigned()->nullable(); |
|
36
|
|
|
$table->smallInteger('active_subscribers_limit')->unsigned()->nullable(); |
|
37
|
|
|
$table->mediumInteger('sort_order')->unsigned()->default(0); |
|
38
|
|
|
$table->timestamps(); |
|
39
|
|
|
$table->softDeletes(); |
|
40
|
|
|
|
|
41
|
|
|
// Indexes |
|
42
|
|
|
$table->unique('slug'); |
|
43
|
|
|
}); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Reverse the migrations. |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function down(): void |
|
52
|
|
|
{ |
|
53
|
|
|
Schema::dropIfExists(config('rinvex.subscriptions.tables.plans')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get jsonable column data type. |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function jsonable(): string |
|
62
|
|
|
{ |
|
63
|
|
|
$driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); |
|
64
|
|
|
$dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); |
|
65
|
|
|
$isOldVersion = version_compare($dbVersion, '5.7.8', 'lt'); |
|
66
|
|
|
|
|
67
|
|
|
return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json'; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|