|
1
|
|
|
<?php |
|
2
|
|
|
namespace App\Db; |
|
3
|
|
|
|
|
4
|
|
|
use App\Model\StatusInterface; |
|
5
|
|
|
use yii\db\Migration as BaseMigration; |
|
6
|
|
|
use yii\db\ColumnSchemaBuilder; |
|
7
|
|
|
|
|
8
|
|
|
class Migration extends BaseMigration |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Returns table options. |
|
12
|
|
|
* |
|
13
|
|
|
* @param string $comment table comment. |
|
14
|
|
|
* |
|
15
|
|
|
* @return string|null table options. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function tableOptions($comment=''): ?string |
|
18
|
|
|
{ |
|
19
|
|
|
$tableOptions = null; |
|
20
|
|
|
if ($this->db->driverName === 'mysql') { |
|
21
|
|
|
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'; |
|
22
|
|
|
if ($comment) { |
|
23
|
|
|
$tableOptions .= ' COMMENT='.$comment; |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
return $tableOptions; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function status(): ColumnSchemaBuilder |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->tinyInteger()->notNull()->defaultValue(StatusInterface::STATUS_ACTIVE)->comment('Status: 0.Inactive 1.Active'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function timestamp($comment = ''): ColumnSchemaBuilder |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->integer()->unsigned()->notNull()->defaultValue(0)->comment($comment); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function createTimestamp(): ColumnSchemaBuilder |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->timestamp('Create Time'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function updateTimestamp(): ColumnSchemaBuilder |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->timestamp('Update Time'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function sorting(): ColumnSchemaBuilder |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->integer()->notNull()->defaultValue(100)->comment('Sorting'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function language(): ColumnSchemaBuilder |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->string(5)->notNull()->comment('Language'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function ipAddress(): ColumnSchemaBuilder |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->string(45)->notNull()->defaultValue('')->comment('IP Address'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function softDelete(): ColumnSchemaBuilder |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->boolean()->notNull()->defaultValue(false)->comment('Is Deleted'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function uuid(): ColumnSchemaBuilder |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->char(36)->notNull()->comment('UUID'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function url($comment = 'URL', $length = null): ColumnSchemaBuilder |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->string($length)->notNull()->defaultValue('')->comment($comment); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function optimisticLock(): ColumnSchemaBuilder |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->bigInteger()->notNull()->defaultValue(0)->comment('Optimistic Lock'); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|