Column.php
4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\db;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Adapter\MysqlAdapter;
class Column extends \Phinx\Db\Table\Column
{
protected $unique = false;
public function setNullable()
{
return $this->setNull(true);
}
public function setUnsigned()
{
return $this->setSigned(false);
}
public function setUnique()
{
$this->unique = true;
return $this;
}
public function getUnique()
{
return $this->unique;
}
public function isUnique()
{
return $this->getUnique();
}
public static function make($name, $type, $options = [])
{
$column = new self();
$column->setName($name);
$column->setType($type);
$column->setOptions($options);
return $column;
}
public static function bigInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_BIG_INTEGER);
}
public static function binary($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_BLOB);
}
public static function boolean($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_BOOLEAN);
}
public static function char($name, $length = 255)
{
return self::make($name, AdapterInterface::PHINX_TYPE_CHAR, compact('length'));
}
public static function date($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_DATE);
}
public static function dateTime($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_DATETIME);
}
public static function decimal($name, $precision = 8, $scale = 2)
{
return self::make($name, AdapterInterface::PHINX_TYPE_DECIMAL, compact('precision', 'scale'));
}
public static function enum($name, array $values)
{
return self::make($name, AdapterInterface::PHINX_TYPE_ENUM, compact('values'));
}
public static function float($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_FLOAT);
}
public static function integer($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER);
}
public static function json($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_JSON);
}
public static function jsonb($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_JSONB);
}
public static function longText($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TEXT, ['length' => MysqlAdapter::TEXT_LONG]);
}
public static function mediumInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER, ['length' => MysqlAdapter::INT_MEDIUM]);
}
public static function mediumText($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TEXT, ['length' => MysqlAdapter::TEXT_MEDIUM]);
}
public static function smallInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER, ['length' => MysqlAdapter::INT_SMALL]);
}
public static function string($name, $length = 255)
{
return self::make($name, AdapterInterface::PHINX_TYPE_STRING, compact('length'));
}
public static function text($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TEXT);
}
public static function time($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TIME);
}
public static function tinyInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER, ['length' => MysqlAdapter::INT_TINY]);
}
public static function unsignedInteger($name)
{
return self::integer($name)->setUnSigned();
}
public static function timestamp($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TIMESTAMP);
}
public static function uuid($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_UUID);
}
}