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
|
|
|
|