1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
namespace rhosocial\user\migrations; |
13
|
|
|
|
14
|
|
|
use rhosocial\user\migrations\mysql\Schema as MySQLSchema; |
15
|
|
|
use yii\db\Schema; |
16
|
|
|
use yii\db\Connection; |
17
|
|
|
use yii\db\ColumnSchemaBuilder; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @version 1.0 |
21
|
|
|
* @author vistart <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
trait SchemaBuilderTrait |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @return Connection the database connection to be used for schema building. |
27
|
|
|
*/ |
28
|
|
|
protected abstract function getDb(); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
* @return ColumnSchemaBuilder |
33
|
|
|
*/ |
34
|
|
|
public function blob() |
35
|
|
|
{ |
36
|
|
|
if ($this->getDb()->driverName == 'mysql') { |
37
|
|
|
return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_BLOB); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
public function binary($length = null) |
45
|
|
|
{ |
46
|
|
|
return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(Schema::TYPE_BINARY, $length); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function varbinary($length = null) |
50
|
|
|
{ |
51
|
|
|
if ($this->getDb()->driverName == 'mysql') { |
52
|
|
|
return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_VARBINARY, $length); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function varchar($length = null) |
57
|
|
|
{ |
58
|
|
|
if ($this->getDb()->driverName == 'mysql') { |
59
|
|
|
return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_VARCHAR, $length); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function binaryPk() |
64
|
|
|
{ |
65
|
|
|
if ($this->getDb()->driverName == 'mysql') { |
66
|
|
|
return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_BINARY_PK); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function tinyInteger($length = null) |
71
|
|
|
{ |
72
|
|
|
if ($this->getDb()->driverName == 'mysql') { |
73
|
|
|
return (new MySQLSchema(['db' => $this->getDb()]))->createColumnSchemaBuilder(MySQLSchema::TYPE_TINYINT, $length); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |