1
|
|
|
<?php namespace Bosnadev\Database\Schema\Grammars; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Fluent; |
4
|
|
|
use Bosnadev\Database\Schema\Blueprint; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class PostgresGrammar |
8
|
|
|
* @package Bosnadev\Database\Schema\Grammars |
9
|
|
|
*/ |
10
|
|
|
class PostgresGrammar extends \Illuminate\Database\Schema\Grammars\PostgresGrammar |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Create the column definition for a character type. |
14
|
|
|
* |
15
|
|
|
* @param Fluent $column |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
3 |
|
protected function typeCharacter(Fluent $column) |
19
|
|
|
{ |
20
|
3 |
|
return "character({$column->length})"; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Create the column definition for a hstore type. |
25
|
|
|
* |
26
|
|
|
* @param Fluent $column |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
3 |
|
protected function typeHstore(Fluent $column) |
|
|
|
|
30
|
|
|
{ |
31
|
3 |
|
return "hstore"; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create the column definition for a uuid type. |
36
|
|
|
* |
37
|
|
|
* @param Fluent $column |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
3 |
|
protected function typeUuid(Fluent $column) |
41
|
|
|
{ |
42
|
3 |
|
return "uuid"; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Create the column definition for a jsonb type. |
47
|
|
|
* |
48
|
|
|
* @param Fluent $column |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
3 |
|
protected function typeJsonb(Fluent $column) |
52
|
|
|
{ |
53
|
3 |
|
return "jsonb"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Create the column definition for an int4range type. |
58
|
|
|
* |
59
|
|
|
* @param Fluent $column |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
3 |
|
protected function typeInt4range(Fluent $column) |
|
|
|
|
64
|
|
|
{ |
65
|
3 |
|
return "int4range"; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Create the column definition for an int8range type. |
70
|
|
|
* |
71
|
|
|
* @param Fluent $column |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
3 |
|
protected function typeInt8range(Fluent $column) |
|
|
|
|
76
|
|
|
{ |
77
|
3 |
|
return "int8range"; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Create the column definition for an numrange type. |
82
|
|
|
* |
83
|
|
|
* @param Fluent $column |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
3 |
|
protected function typeNumrange(Fluent $column) |
|
|
|
|
88
|
|
|
{ |
89
|
3 |
|
return "numrange"; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Create the column definition for an tsrange type. |
94
|
|
|
* |
95
|
|
|
* @param Fluent $column |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
3 |
|
protected function typeTsrange(Fluent $column) |
|
|
|
|
100
|
|
|
{ |
101
|
3 |
|
return "tsrange"; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Create the column definition for an tstzrange type. |
106
|
|
|
* |
107
|
|
|
* @param Fluent $column |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
3 |
|
protected function typeTstzrange(Fluent $column) |
|
|
|
|
112
|
|
|
{ |
113
|
3 |
|
return "tstzrange"; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Create the column definition for an daterange type. |
118
|
|
|
* |
119
|
|
|
* @param Fluent $column |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
3 |
|
protected function typeDaterange(Fluent $column) |
|
|
|
|
124
|
|
|
{ |
125
|
3 |
|
return "daterange"; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Create the column definition for an inet type. |
130
|
|
|
* |
131
|
|
|
* @param Fluent $column |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
protected function typeInet(Fluent $column) |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
return "inet"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param mixed $value |
142
|
|
|
* @return mixed|string |
143
|
|
|
*/ |
144
|
|
|
protected function getDefaultValue($value) |
145
|
|
|
{ |
146
|
|
|
if($this->isUuid($value)) return strval($value); |
147
|
|
|
|
148
|
|
|
return parent::getDefaultValue($value); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Check if string matches on of uuid_generate functions |
153
|
|
|
* |
154
|
|
|
* @param $value |
155
|
|
|
* @return int |
156
|
|
|
*/ |
157
|
3 |
|
protected function isUuid($value) |
158
|
|
|
{ |
159
|
3 |
|
return preg_match('/^uuid_generate_v/', $value); |
160
|
|
|
} |
161
|
3 |
|
|
162
|
|
|
/** |
163
|
|
|
* Compile a gin index key command. |
164
|
|
|
* |
165
|
|
|
* @param \Bosnadev\Database\Schema\Blueprint $blueprint |
166
|
|
|
* @param \Illuminate\Support\Fluent $command |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
|
|
public function compileGin(Blueprint $blueprint, Fluent $command) |
170
|
|
|
{ |
171
|
|
|
$columns = $this->columnize($command->columns); |
172
|
|
|
|
173
|
|
|
return sprintf('CREATE INDEX %s ON %s USING GIN(%s)', $command->index, $this->wrapTable($blueprint), $columns); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.