1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cycle\Migrations\V2; |
6
|
|
|
|
7
|
|
|
trait ColumnTrait |
8
|
|
|
{ |
9
|
|
|
protected function primaryKey($length = null): Column |
10
|
|
|
{ |
11
|
|
|
$column = new Column(ColumnType::TYPE_PK, $length); |
12
|
|
|
$column->notNull(); |
13
|
|
|
|
14
|
|
|
return $column; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
protected function bigPrimaryKey($length = null): Column |
18
|
|
|
{ |
19
|
|
|
$column = new Column(ColumnType::TYPE_BIGPK, $length); |
20
|
|
|
$column->notNull(); |
21
|
|
|
|
22
|
|
|
return $column; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function string($length = null): Column |
26
|
|
|
{ |
27
|
|
|
return new Column(ColumnType::TYPE_STRING, $length); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function text(): Column |
31
|
|
|
{ |
32
|
|
|
return new Column(ColumnType::TYPE_TEXT); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function integer($length = null): Column |
36
|
|
|
{ |
37
|
|
|
return new Column(ColumnType::TYPE_INTEGER, $length); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function bigInteger($length = null): Column |
41
|
|
|
{ |
42
|
|
|
return new Column(ColumnType::TYPE_BIGINT, $length); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function numeric($precision = null): Column |
46
|
|
|
{ |
47
|
|
|
return new Column(ColumnType::TYPE_NUMERIC, $precision); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function dateTime(): Column |
51
|
|
|
{ |
52
|
|
|
return new Column(ColumnType::TYPE_DATETIME); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function boolean(): Column |
56
|
|
|
{ |
57
|
|
|
return new Column(ColumnType::TYPE_BOOLEAN); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function money(): Column |
61
|
|
|
{ |
62
|
|
|
return new Column(ColumnType::TYPE_MONEY); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function json(): Column |
66
|
|
|
{ |
67
|
|
|
return new Column(ColumnType::TYPE_JSON); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function point(): Column |
71
|
|
|
{ |
72
|
|
|
return new Column(ColumnType::TYPE_POINT); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function customType(string $type): Column |
76
|
|
|
{ |
77
|
|
|
return new Column($type); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|