| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Illuminate\Database\Schema\Grammars;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Database\Connection;
|
|
|
6 |
use Illuminate\Database\Schema\Blueprint;
|
|
|
7 |
use Illuminate\Support\Fluent;
|
|
|
8 |
use RuntimeException;
|
|
|
9 |
|
|
|
10 |
class MySqlGrammar extends Grammar
|
|
|
11 |
{
|
|
|
12 |
/**
|
|
|
13 |
* The possible column modifiers.
|
|
|
14 |
*
|
|
|
15 |
* @var string[]
|
|
|
16 |
*/
|
|
|
17 |
protected $modifiers = [
|
|
|
18 |
'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable', 'Invisible',
|
|
|
19 |
'Srid', 'Default', 'Increment', 'Comment', 'After', 'First',
|
|
|
20 |
];
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* The possible column serials.
|
|
|
24 |
*
|
|
|
25 |
* @var string[]
|
|
|
26 |
*/
|
|
|
27 |
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Compile a create database command.
|
|
|
31 |
*
|
|
|
32 |
* @param string $name
|
|
|
33 |
* @param \Illuminate\Database\Connection $connection
|
|
|
34 |
* @return string
|
|
|
35 |
*/
|
|
|
36 |
public function compileCreateDatabase($name, $connection)
|
|
|
37 |
{
|
|
|
38 |
return sprintf(
|
|
|
39 |
'create database %s default character set %s default collate %s',
|
|
|
40 |
$this->wrapValue($name),
|
|
|
41 |
$this->wrapValue($connection->getConfig('charset')),
|
|
|
42 |
$this->wrapValue($connection->getConfig('collation')),
|
|
|
43 |
);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Compile a drop database if exists command.
|
|
|
48 |
*
|
|
|
49 |
* @param string $name
|
|
|
50 |
* @return string
|
|
|
51 |
*/
|
|
|
52 |
public function compileDropDatabaseIfExists($name)
|
|
|
53 |
{
|
|
|
54 |
return sprintf(
|
|
|
55 |
'drop database if exists %s',
|
|
|
56 |
$this->wrapValue($name)
|
|
|
57 |
);
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Compile the query to determine the list of tables.
|
|
|
62 |
*
|
|
|
63 |
* @return string
|
|
|
64 |
*/
|
|
|
65 |
public function compileTableExists()
|
|
|
66 |
{
|
|
|
67 |
return "select * from information_schema.tables where table_schema = ? and table_name = ? and table_type = 'BASE TABLE'";
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Compile the query to determine the list of columns.
|
|
|
72 |
*
|
|
|
73 |
* @return string
|
|
|
74 |
*/
|
|
|
75 |
public function compileColumnListing()
|
|
|
76 |
{
|
|
|
77 |
return 'select column_name as `column_name` from information_schema.columns where table_schema = ? and table_name = ?';
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Compile a create table command.
|
|
|
82 |
*
|
|
|
83 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
84 |
* @param \Illuminate\Support\Fluent $command
|
|
|
85 |
* @param \Illuminate\Database\Connection $connection
|
|
|
86 |
* @return array
|
|
|
87 |
*/
|
|
|
88 |
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
|
|
|
89 |
{
|
|
|
90 |
$sql = $this->compileCreateTable(
|
|
|
91 |
$blueprint, $command, $connection
|
|
|
92 |
);
|
|
|
93 |
|
|
|
94 |
// Once we have the primary SQL, we can add the encoding option to the SQL for
|
|
|
95 |
// the table. Then, we can check if a storage engine has been supplied for
|
|
|
96 |
// the table. If so, we will add the engine declaration to the SQL query.
|
|
|
97 |
$sql = $this->compileCreateEncoding(
|
|
|
98 |
$sql, $connection, $blueprint
|
|
|
99 |
);
|
|
|
100 |
|
|
|
101 |
// Finally, we will append the engine configuration onto this SQL statement as
|
|
|
102 |
// the final thing we do before returning this finished SQL. Once this gets
|
|
|
103 |
// added the query will be ready to execute against the real connections.
|
|
|
104 |
return array_values(array_filter(array_merge([$this->compileCreateEngine(
|
|
|
105 |
$sql, $connection, $blueprint
|
|
|
106 |
)], $this->compileAutoIncrementStartingValues($blueprint))));
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Create the main create table clause.
|
|
|
111 |
*
|
|
|
112 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
113 |
* @param \Illuminate\Support\Fluent $command
|
|
|
114 |
* @param \Illuminate\Database\Connection $connection
|
|
|
115 |
* @return array
|
|
|
116 |
*/
|
|
|
117 |
protected function compileCreateTable($blueprint, $command, $connection)
|
|
|
118 |
{
|
|
|
119 |
return trim(sprintf('%s table %s (%s)',
|
|
|
120 |
$blueprint->temporary ? 'create temporary' : 'create',
|
|
|
121 |
$this->wrapTable($blueprint),
|
|
|
122 |
implode(', ', $this->getColumns($blueprint))
|
|
|
123 |
));
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Append the character set specifications to a command.
|
|
|
128 |
*
|
|
|
129 |
* @param string $sql
|
|
|
130 |
* @param \Illuminate\Database\Connection $connection
|
|
|
131 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
132 |
* @return string
|
|
|
133 |
*/
|
|
|
134 |
protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint)
|
|
|
135 |
{
|
|
|
136 |
// First we will set the character set if one has been set on either the create
|
|
|
137 |
// blueprint itself or on the root configuration for the connection that the
|
|
|
138 |
// table is being created on. We will add these to the create table query.
|
|
|
139 |
if (isset($blueprint->charset)) {
|
|
|
140 |
$sql .= ' default character set '.$blueprint->charset;
|
|
|
141 |
} elseif (! is_null($charset = $connection->getConfig('charset'))) {
|
|
|
142 |
$sql .= ' default character set '.$charset;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
// Next we will add the collation to the create table statement if one has been
|
|
|
146 |
// added to either this create table blueprint or the configuration for this
|
|
|
147 |
// connection that the query is targeting. We'll add it to this SQL query.
|
|
|
148 |
if (isset($blueprint->collation)) {
|
|
|
149 |
$sql .= " collate '{$blueprint->collation}'";
|
|
|
150 |
} elseif (! is_null($collation = $connection->getConfig('collation'))) {
|
|
|
151 |
$sql .= " collate '{$collation}'";
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
return $sql;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
/**
|
|
|
158 |
* Append the engine specifications to a command.
|
|
|
159 |
*
|
|
|
160 |
* @param string $sql
|
|
|
161 |
* @param \Illuminate\Database\Connection $connection
|
|
|
162 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
163 |
* @return string
|
|
|
164 |
*/
|
|
|
165 |
protected function compileCreateEngine($sql, Connection $connection, Blueprint $blueprint)
|
|
|
166 |
{
|
|
|
167 |
if (isset($blueprint->engine)) {
|
|
|
168 |
return $sql.' engine = '.$blueprint->engine;
|
|
|
169 |
} elseif (! is_null($engine = $connection->getConfig('engine'))) {
|
|
|
170 |
return $sql.' engine = '.$engine;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
return $sql;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
/**
|
|
|
177 |
* Compile an add column command.
|
|
|
178 |
*
|
|
|
179 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
180 |
* @param \Illuminate\Support\Fluent $command
|
|
|
181 |
* @return array
|
|
|
182 |
*/
|
|
|
183 |
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
|
|
184 |
{
|
|
|
185 |
$columns = $this->prefixArray('add', $this->getColumns($blueprint));
|
|
|
186 |
|
|
|
187 |
return array_values(array_merge(
|
|
|
188 |
['alter table '.$this->wrapTable($blueprint).' '.implode(', ', $columns)],
|
|
|
189 |
$this->compileAutoIncrementStartingValues($blueprint)
|
|
|
190 |
));
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
/**
|
|
|
194 |
* Compile the auto-incrementing column starting values.
|
|
|
195 |
*
|
|
|
196 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
197 |
* @return array
|
|
|
198 |
*/
|
|
|
199 |
public function compileAutoIncrementStartingValues(Blueprint $blueprint)
|
|
|
200 |
{
|
|
|
201 |
return collect($blueprint->autoIncrementingStartingValues())->map(function ($value, $column) use ($blueprint) {
|
|
|
202 |
return 'alter table '.$this->wrapTable($blueprint->getTable()).' auto_increment = '.$value;
|
|
|
203 |
})->all();
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* Compile a rename column command.
|
|
|
208 |
*
|
|
|
209 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
210 |
* @param \Illuminate\Support\Fluent $command
|
|
|
211 |
* @param \Illuminate\Database\Connection $connection
|
|
|
212 |
* @return array|string
|
|
|
213 |
*/
|
|
|
214 |
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
|
|
|
215 |
{
|
|
|
216 |
return $connection->usingNativeSchemaOperations()
|
|
|
217 |
? sprintf('alter table %s rename column %s to %s',
|
|
|
218 |
$this->wrapTable($blueprint),
|
|
|
219 |
$this->wrap($command->from),
|
|
|
220 |
$this->wrap($command->to)
|
|
|
221 |
)
|
|
|
222 |
: parent::compileRenameColumn($blueprint, $command, $connection);
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
/**
|
|
|
226 |
* Compile a primary key command.
|
|
|
227 |
*
|
|
|
228 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
229 |
* @param \Illuminate\Support\Fluent $command
|
|
|
230 |
* @return string
|
|
|
231 |
*/
|
|
|
232 |
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
|
|
233 |
{
|
|
|
234 |
return sprintf('alter table %s add primary key %s(%s)',
|
|
|
235 |
$this->wrapTable($blueprint),
|
|
|
236 |
$command->algorithm ? 'using '.$command->algorithm : '',
|
|
|
237 |
$this->columnize($command->columns)
|
|
|
238 |
);
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
/**
|
|
|
242 |
* Compile a unique key command.
|
|
|
243 |
*
|
|
|
244 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
245 |
* @param \Illuminate\Support\Fluent $command
|
|
|
246 |
* @return string
|
|
|
247 |
*/
|
|
|
248 |
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
|
|
249 |
{
|
|
|
250 |
return $this->compileKey($blueprint, $command, 'unique');
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
/**
|
|
|
254 |
* Compile a plain index key command.
|
|
|
255 |
*
|
|
|
256 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
257 |
* @param \Illuminate\Support\Fluent $command
|
|
|
258 |
* @return string
|
|
|
259 |
*/
|
|
|
260 |
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
|
|
261 |
{
|
|
|
262 |
return $this->compileKey($blueprint, $command, 'index');
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
/**
|
|
|
266 |
* Compile a fulltext index key command.
|
|
|
267 |
*
|
|
|
268 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
269 |
* @param \Illuminate\Support\Fluent $command
|
|
|
270 |
* @return string
|
|
|
271 |
*/
|
|
|
272 |
public function compileFullText(Blueprint $blueprint, Fluent $command)
|
|
|
273 |
{
|
|
|
274 |
return $this->compileKey($blueprint, $command, 'fulltext');
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
/**
|
|
|
278 |
* Compile a spatial index key command.
|
|
|
279 |
*
|
|
|
280 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
281 |
* @param \Illuminate\Support\Fluent $command
|
|
|
282 |
* @return string
|
|
|
283 |
*/
|
|
|
284 |
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
|
|
|
285 |
{
|
|
|
286 |
return $this->compileKey($blueprint, $command, 'spatial index');
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
/**
|
|
|
290 |
* Compile an index creation command.
|
|
|
291 |
*
|
|
|
292 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
293 |
* @param \Illuminate\Support\Fluent $command
|
|
|
294 |
* @param string $type
|
|
|
295 |
* @return string
|
|
|
296 |
*/
|
|
|
297 |
protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
|
|
|
298 |
{
|
|
|
299 |
return sprintf('alter table %s add %s %s%s(%s)',
|
|
|
300 |
$this->wrapTable($blueprint),
|
|
|
301 |
$type,
|
|
|
302 |
$this->wrap($command->index),
|
|
|
303 |
$command->algorithm ? ' using '.$command->algorithm : '',
|
|
|
304 |
$this->columnize($command->columns)
|
|
|
305 |
);
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
/**
|
|
|
309 |
* Compile a drop table command.
|
|
|
310 |
*
|
|
|
311 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
312 |
* @param \Illuminate\Support\Fluent $command
|
|
|
313 |
* @return string
|
|
|
314 |
*/
|
|
|
315 |
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
|
|
316 |
{
|
|
|
317 |
return 'drop table '.$this->wrapTable($blueprint);
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
/**
|
|
|
321 |
* Compile a drop table (if exists) command.
|
|
|
322 |
*
|
|
|
323 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
324 |
* @param \Illuminate\Support\Fluent $command
|
|
|
325 |
* @return string
|
|
|
326 |
*/
|
|
|
327 |
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
|
|
|
328 |
{
|
|
|
329 |
return 'drop table if exists '.$this->wrapTable($blueprint);
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
/**
|
|
|
333 |
* Compile a drop column command.
|
|
|
334 |
*
|
|
|
335 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
336 |
* @param \Illuminate\Support\Fluent $command
|
|
|
337 |
* @return string
|
|
|
338 |
*/
|
|
|
339 |
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
|
|
340 |
{
|
|
|
341 |
$columns = $this->prefixArray('drop', $this->wrapArray($command->columns));
|
|
|
342 |
|
|
|
343 |
return 'alter table '.$this->wrapTable($blueprint).' '.implode(', ', $columns);
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
/**
|
|
|
347 |
* Compile a drop primary key command.
|
|
|
348 |
*
|
|
|
349 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
350 |
* @param \Illuminate\Support\Fluent $command
|
|
|
351 |
* @return string
|
|
|
352 |
*/
|
|
|
353 |
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
|
|
|
354 |
{
|
|
|
355 |
return 'alter table '.$this->wrapTable($blueprint).' drop primary key';
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
/**
|
|
|
359 |
* Compile a drop unique key command.
|
|
|
360 |
*
|
|
|
361 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
362 |
* @param \Illuminate\Support\Fluent $command
|
|
|
363 |
* @return string
|
|
|
364 |
*/
|
|
|
365 |
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
|
|
366 |
{
|
|
|
367 |
$index = $this->wrap($command->index);
|
|
|
368 |
|
|
|
369 |
return "alter table {$this->wrapTable($blueprint)} drop index {$index}";
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
/**
|
|
|
373 |
* Compile a drop index command.
|
|
|
374 |
*
|
|
|
375 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
376 |
* @param \Illuminate\Support\Fluent $command
|
|
|
377 |
* @return string
|
|
|
378 |
*/
|
|
|
379 |
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
|
|
380 |
{
|
|
|
381 |
$index = $this->wrap($command->index);
|
|
|
382 |
|
|
|
383 |
return "alter table {$this->wrapTable($blueprint)} drop index {$index}";
|
|
|
384 |
}
|
|
|
385 |
|
|
|
386 |
/**
|
|
|
387 |
* Compile a drop fulltext index command.
|
|
|
388 |
*
|
|
|
389 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
390 |
* @param \Illuminate\Support\Fluent $command
|
|
|
391 |
* @return string
|
|
|
392 |
*/
|
|
|
393 |
public function compileDropFullText(Blueprint $blueprint, Fluent $command)
|
|
|
394 |
{
|
|
|
395 |
return $this->compileDropIndex($blueprint, $command);
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
/**
|
|
|
399 |
* Compile a drop spatial index command.
|
|
|
400 |
*
|
|
|
401 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
402 |
* @param \Illuminate\Support\Fluent $command
|
|
|
403 |
* @return string
|
|
|
404 |
*/
|
|
|
405 |
public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
|
|
|
406 |
{
|
|
|
407 |
return $this->compileDropIndex($blueprint, $command);
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
/**
|
|
|
411 |
* Compile a drop foreign key command.
|
|
|
412 |
*
|
|
|
413 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
414 |
* @param \Illuminate\Support\Fluent $command
|
|
|
415 |
* @return string
|
|
|
416 |
*/
|
|
|
417 |
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
|
|
418 |
{
|
|
|
419 |
$index = $this->wrap($command->index);
|
|
|
420 |
|
|
|
421 |
return "alter table {$this->wrapTable($blueprint)} drop foreign key {$index}";
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
/**
|
|
|
425 |
* Compile a rename table command.
|
|
|
426 |
*
|
|
|
427 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
428 |
* @param \Illuminate\Support\Fluent $command
|
|
|
429 |
* @return string
|
|
|
430 |
*/
|
|
|
431 |
public function compileRename(Blueprint $blueprint, Fluent $command)
|
|
|
432 |
{
|
|
|
433 |
$from = $this->wrapTable($blueprint);
|
|
|
434 |
|
|
|
435 |
return "rename table {$from} to ".$this->wrapTable($command->to);
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
/**
|
|
|
439 |
* Compile a rename index command.
|
|
|
440 |
*
|
|
|
441 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
442 |
* @param \Illuminate\Support\Fluent $command
|
|
|
443 |
* @return string
|
|
|
444 |
*/
|
|
|
445 |
public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
|
|
|
446 |
{
|
|
|
447 |
return sprintf('alter table %s rename index %s to %s',
|
|
|
448 |
$this->wrapTable($blueprint),
|
|
|
449 |
$this->wrap($command->from),
|
|
|
450 |
$this->wrap($command->to)
|
|
|
451 |
);
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
/**
|
|
|
455 |
* Compile the SQL needed to drop all tables.
|
|
|
456 |
*
|
|
|
457 |
* @param array $tables
|
|
|
458 |
* @return string
|
|
|
459 |
*/
|
|
|
460 |
public function compileDropAllTables($tables)
|
|
|
461 |
{
|
|
|
462 |
return 'drop table '.implode(',', $this->wrapArray($tables));
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
/**
|
|
|
466 |
* Compile the SQL needed to drop all views.
|
|
|
467 |
*
|
|
|
468 |
* @param array $views
|
|
|
469 |
* @return string
|
|
|
470 |
*/
|
|
|
471 |
public function compileDropAllViews($views)
|
|
|
472 |
{
|
|
|
473 |
return 'drop view '.implode(',', $this->wrapArray($views));
|
|
|
474 |
}
|
|
|
475 |
|
|
|
476 |
/**
|
|
|
477 |
* Compile the SQL needed to retrieve all table names.
|
|
|
478 |
*
|
|
|
479 |
* @return string
|
|
|
480 |
*/
|
|
|
481 |
public function compileGetAllTables()
|
|
|
482 |
{
|
|
|
483 |
return 'SHOW FULL TABLES WHERE table_type = \'BASE TABLE\'';
|
|
|
484 |
}
|
|
|
485 |
|
|
|
486 |
/**
|
|
|
487 |
* Compile the SQL needed to retrieve all view names.
|
|
|
488 |
*
|
|
|
489 |
* @return string
|
|
|
490 |
*/
|
|
|
491 |
public function compileGetAllViews()
|
|
|
492 |
{
|
|
|
493 |
return 'SHOW FULL TABLES WHERE table_type = \'VIEW\'';
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
/**
|
|
|
497 |
* Compile the command to enable foreign key constraints.
|
|
|
498 |
*
|
|
|
499 |
* @return string
|
|
|
500 |
*/
|
|
|
501 |
public function compileEnableForeignKeyConstraints()
|
|
|
502 |
{
|
|
|
503 |
return 'SET FOREIGN_KEY_CHECKS=1;';
|
|
|
504 |
}
|
|
|
505 |
|
|
|
506 |
/**
|
|
|
507 |
* Compile the command to disable foreign key constraints.
|
|
|
508 |
*
|
|
|
509 |
* @return string
|
|
|
510 |
*/
|
|
|
511 |
public function compileDisableForeignKeyConstraints()
|
|
|
512 |
{
|
|
|
513 |
return 'SET FOREIGN_KEY_CHECKS=0;';
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
/**
|
|
|
517 |
* Compile a table comment command.
|
|
|
518 |
*
|
|
|
519 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
520 |
* @param \Illuminate\Support\Fluent $command
|
|
|
521 |
* @return string
|
|
|
522 |
*/
|
|
|
523 |
public function compileTableComment(Blueprint $blueprint, Fluent $command)
|
|
|
524 |
{
|
|
|
525 |
return sprintf('alter table %s comment = %s',
|
|
|
526 |
$this->wrapTable($blueprint),
|
|
|
527 |
"'".str_replace("'", "''", $command->comment)."'"
|
|
|
528 |
);
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
/**
|
|
|
532 |
* Create the column definition for a char type.
|
|
|
533 |
*
|
|
|
534 |
* @param \Illuminate\Support\Fluent $column
|
|
|
535 |
* @return string
|
|
|
536 |
*/
|
|
|
537 |
protected function typeChar(Fluent $column)
|
|
|
538 |
{
|
|
|
539 |
return "char({$column->length})";
|
|
|
540 |
}
|
|
|
541 |
|
|
|
542 |
/**
|
|
|
543 |
* Create the column definition for a string type.
|
|
|
544 |
*
|
|
|
545 |
* @param \Illuminate\Support\Fluent $column
|
|
|
546 |
* @return string
|
|
|
547 |
*/
|
|
|
548 |
protected function typeString(Fluent $column)
|
|
|
549 |
{
|
|
|
550 |
return "varchar({$column->length})";
|
|
|
551 |
}
|
|
|
552 |
|
|
|
553 |
/**
|
|
|
554 |
* Create the column definition for a tiny text type.
|
|
|
555 |
*
|
|
|
556 |
* @param \Illuminate\Support\Fluent $column
|
|
|
557 |
* @return string
|
|
|
558 |
*/
|
|
|
559 |
protected function typeTinyText(Fluent $column)
|
|
|
560 |
{
|
|
|
561 |
return 'tinytext';
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
/**
|
|
|
565 |
* Create the column definition for a text type.
|
|
|
566 |
*
|
|
|
567 |
* @param \Illuminate\Support\Fluent $column
|
|
|
568 |
* @return string
|
|
|
569 |
*/
|
|
|
570 |
protected function typeText(Fluent $column)
|
|
|
571 |
{
|
|
|
572 |
return 'text';
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
/**
|
|
|
576 |
* Create the column definition for a medium text type.
|
|
|
577 |
*
|
|
|
578 |
* @param \Illuminate\Support\Fluent $column
|
|
|
579 |
* @return string
|
|
|
580 |
*/
|
|
|
581 |
protected function typeMediumText(Fluent $column)
|
|
|
582 |
{
|
|
|
583 |
return 'mediumtext';
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
/**
|
|
|
587 |
* Create the column definition for a long text type.
|
|
|
588 |
*
|
|
|
589 |
* @param \Illuminate\Support\Fluent $column
|
|
|
590 |
* @return string
|
|
|
591 |
*/
|
|
|
592 |
protected function typeLongText(Fluent $column)
|
|
|
593 |
{
|
|
|
594 |
return 'longtext';
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
/**
|
|
|
598 |
* Create the column definition for a big integer type.
|
|
|
599 |
*
|
|
|
600 |
* @param \Illuminate\Support\Fluent $column
|
|
|
601 |
* @return string
|
|
|
602 |
*/
|
|
|
603 |
protected function typeBigInteger(Fluent $column)
|
|
|
604 |
{
|
|
|
605 |
return 'bigint';
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
/**
|
|
|
609 |
* Create the column definition for an integer type.
|
|
|
610 |
*
|
|
|
611 |
* @param \Illuminate\Support\Fluent $column
|
|
|
612 |
* @return string
|
|
|
613 |
*/
|
|
|
614 |
protected function typeInteger(Fluent $column)
|
|
|
615 |
{
|
|
|
616 |
return 'int';
|
|
|
617 |
}
|
|
|
618 |
|
|
|
619 |
/**
|
|
|
620 |
* Create the column definition for a medium integer type.
|
|
|
621 |
*
|
|
|
622 |
* @param \Illuminate\Support\Fluent $column
|
|
|
623 |
* @return string
|
|
|
624 |
*/
|
|
|
625 |
protected function typeMediumInteger(Fluent $column)
|
|
|
626 |
{
|
|
|
627 |
return 'mediumint';
|
|
|
628 |
}
|
|
|
629 |
|
|
|
630 |
/**
|
|
|
631 |
* Create the column definition for a tiny integer type.
|
|
|
632 |
*
|
|
|
633 |
* @param \Illuminate\Support\Fluent $column
|
|
|
634 |
* @return string
|
|
|
635 |
*/
|
|
|
636 |
protected function typeTinyInteger(Fluent $column)
|
|
|
637 |
{
|
|
|
638 |
return 'tinyint';
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
/**
|
|
|
642 |
* Create the column definition for a small integer type.
|
|
|
643 |
*
|
|
|
644 |
* @param \Illuminate\Support\Fluent $column
|
|
|
645 |
* @return string
|
|
|
646 |
*/
|
|
|
647 |
protected function typeSmallInteger(Fluent $column)
|
|
|
648 |
{
|
|
|
649 |
return 'smallint';
|
|
|
650 |
}
|
|
|
651 |
|
|
|
652 |
/**
|
|
|
653 |
* Create the column definition for a float type.
|
|
|
654 |
*
|
|
|
655 |
* @param \Illuminate\Support\Fluent $column
|
|
|
656 |
* @return string
|
|
|
657 |
*/
|
|
|
658 |
protected function typeFloat(Fluent $column)
|
|
|
659 |
{
|
|
|
660 |
return $this->typeDouble($column);
|
|
|
661 |
}
|
|
|
662 |
|
|
|
663 |
/**
|
|
|
664 |
* Create the column definition for a double type.
|
|
|
665 |
*
|
|
|
666 |
* @param \Illuminate\Support\Fluent $column
|
|
|
667 |
* @return string
|
|
|
668 |
*/
|
|
|
669 |
protected function typeDouble(Fluent $column)
|
|
|
670 |
{
|
|
|
671 |
if ($column->total && $column->places) {
|
|
|
672 |
return "double({$column->total}, {$column->places})";
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
return 'double';
|
|
|
676 |
}
|
|
|
677 |
|
|
|
678 |
/**
|
|
|
679 |
* Create the column definition for a decimal type.
|
|
|
680 |
*
|
|
|
681 |
* @param \Illuminate\Support\Fluent $column
|
|
|
682 |
* @return string
|
|
|
683 |
*/
|
|
|
684 |
protected function typeDecimal(Fluent $column)
|
|
|
685 |
{
|
|
|
686 |
return "decimal({$column->total}, {$column->places})";
|
|
|
687 |
}
|
|
|
688 |
|
|
|
689 |
/**
|
|
|
690 |
* Create the column definition for a boolean type.
|
|
|
691 |
*
|
|
|
692 |
* @param \Illuminate\Support\Fluent $column
|
|
|
693 |
* @return string
|
|
|
694 |
*/
|
|
|
695 |
protected function typeBoolean(Fluent $column)
|
|
|
696 |
{
|
|
|
697 |
return 'tinyint(1)';
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
/**
|
|
|
701 |
* Create the column definition for an enumeration type.
|
|
|
702 |
*
|
|
|
703 |
* @param \Illuminate\Support\Fluent $column
|
|
|
704 |
* @return string
|
|
|
705 |
*/
|
|
|
706 |
protected function typeEnum(Fluent $column)
|
|
|
707 |
{
|
|
|
708 |
return sprintf('enum(%s)', $this->quoteString($column->allowed));
|
|
|
709 |
}
|
|
|
710 |
|
|
|
711 |
/**
|
|
|
712 |
* Create the column definition for a set enumeration type.
|
|
|
713 |
*
|
|
|
714 |
* @param \Illuminate\Support\Fluent $column
|
|
|
715 |
* @return string
|
|
|
716 |
*/
|
|
|
717 |
protected function typeSet(Fluent $column)
|
|
|
718 |
{
|
|
|
719 |
return sprintf('set(%s)', $this->quoteString($column->allowed));
|
|
|
720 |
}
|
|
|
721 |
|
|
|
722 |
/**
|
|
|
723 |
* Create the column definition for a json type.
|
|
|
724 |
*
|
|
|
725 |
* @param \Illuminate\Support\Fluent $column
|
|
|
726 |
* @return string
|
|
|
727 |
*/
|
|
|
728 |
protected function typeJson(Fluent $column)
|
|
|
729 |
{
|
|
|
730 |
return 'json';
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
/**
|
|
|
734 |
* Create the column definition for a jsonb type.
|
|
|
735 |
*
|
|
|
736 |
* @param \Illuminate\Support\Fluent $column
|
|
|
737 |
* @return string
|
|
|
738 |
*/
|
|
|
739 |
protected function typeJsonb(Fluent $column)
|
|
|
740 |
{
|
|
|
741 |
return 'json';
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
/**
|
|
|
745 |
* Create the column definition for a date type.
|
|
|
746 |
*
|
|
|
747 |
* @param \Illuminate\Support\Fluent $column
|
|
|
748 |
* @return string
|
|
|
749 |
*/
|
|
|
750 |
protected function typeDate(Fluent $column)
|
|
|
751 |
{
|
|
|
752 |
return 'date';
|
|
|
753 |
}
|
|
|
754 |
|
|
|
755 |
/**
|
|
|
756 |
* Create the column definition for a date-time type.
|
|
|
757 |
*
|
|
|
758 |
* @param \Illuminate\Support\Fluent $column
|
|
|
759 |
* @return string
|
|
|
760 |
*/
|
|
|
761 |
protected function typeDateTime(Fluent $column)
|
|
|
762 |
{
|
|
|
763 |
$columnType = $column->precision ? "datetime($column->precision)" : 'datetime';
|
|
|
764 |
|
|
|
765 |
$current = $column->precision ? "CURRENT_TIMESTAMP($column->precision)" : 'CURRENT_TIMESTAMP';
|
|
|
766 |
|
|
|
767 |
$columnType = $column->useCurrent ? "$columnType default $current" : $columnType;
|
|
|
768 |
|
|
|
769 |
return $column->useCurrentOnUpdate ? "$columnType on update $current" : $columnType;
|
|
|
770 |
}
|
|
|
771 |
|
|
|
772 |
/**
|
|
|
773 |
* Create the column definition for a date-time (with time zone) type.
|
|
|
774 |
*
|
|
|
775 |
* @param \Illuminate\Support\Fluent $column
|
|
|
776 |
* @return string
|
|
|
777 |
*/
|
|
|
778 |
protected function typeDateTimeTz(Fluent $column)
|
|
|
779 |
{
|
|
|
780 |
return $this->typeDateTime($column);
|
|
|
781 |
}
|
|
|
782 |
|
|
|
783 |
/**
|
|
|
784 |
* Create the column definition for a time type.
|
|
|
785 |
*
|
|
|
786 |
* @param \Illuminate\Support\Fluent $column
|
|
|
787 |
* @return string
|
|
|
788 |
*/
|
|
|
789 |
protected function typeTime(Fluent $column)
|
|
|
790 |
{
|
|
|
791 |
return $column->precision ? "time($column->precision)" : 'time';
|
|
|
792 |
}
|
|
|
793 |
|
|
|
794 |
/**
|
|
|
795 |
* Create the column definition for a time (with time zone) type.
|
|
|
796 |
*
|
|
|
797 |
* @param \Illuminate\Support\Fluent $column
|
|
|
798 |
* @return string
|
|
|
799 |
*/
|
|
|
800 |
protected function typeTimeTz(Fluent $column)
|
|
|
801 |
{
|
|
|
802 |
return $this->typeTime($column);
|
|
|
803 |
}
|
|
|
804 |
|
|
|
805 |
/**
|
|
|
806 |
* Create the column definition for a timestamp type.
|
|
|
807 |
*
|
|
|
808 |
* @param \Illuminate\Support\Fluent $column
|
|
|
809 |
* @return string
|
|
|
810 |
*/
|
|
|
811 |
protected function typeTimestamp(Fluent $column)
|
|
|
812 |
{
|
|
|
813 |
$columnType = $column->precision ? "timestamp($column->precision)" : 'timestamp';
|
|
|
814 |
|
|
|
815 |
$current = $column->precision ? "CURRENT_TIMESTAMP($column->precision)" : 'CURRENT_TIMESTAMP';
|
|
|
816 |
|
|
|
817 |
$columnType = $column->useCurrent ? "$columnType default $current" : $columnType;
|
|
|
818 |
|
|
|
819 |
return $column->useCurrentOnUpdate ? "$columnType on update $current" : $columnType;
|
|
|
820 |
}
|
|
|
821 |
|
|
|
822 |
/**
|
|
|
823 |
* Create the column definition for a timestamp (with time zone) type.
|
|
|
824 |
*
|
|
|
825 |
* @param \Illuminate\Support\Fluent $column
|
|
|
826 |
* @return string
|
|
|
827 |
*/
|
|
|
828 |
protected function typeTimestampTz(Fluent $column)
|
|
|
829 |
{
|
|
|
830 |
return $this->typeTimestamp($column);
|
|
|
831 |
}
|
|
|
832 |
|
|
|
833 |
/**
|
|
|
834 |
* Create the column definition for a year type.
|
|
|
835 |
*
|
|
|
836 |
* @param \Illuminate\Support\Fluent $column
|
|
|
837 |
* @return string
|
|
|
838 |
*/
|
|
|
839 |
protected function typeYear(Fluent $column)
|
|
|
840 |
{
|
|
|
841 |
return 'year';
|
|
|
842 |
}
|
|
|
843 |
|
|
|
844 |
/**
|
|
|
845 |
* Create the column definition for a binary type.
|
|
|
846 |
*
|
|
|
847 |
* @param \Illuminate\Support\Fluent $column
|
|
|
848 |
* @return string
|
|
|
849 |
*/
|
|
|
850 |
protected function typeBinary(Fluent $column)
|
|
|
851 |
{
|
|
|
852 |
return 'blob';
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
/**
|
|
|
856 |
* Create the column definition for a uuid type.
|
|
|
857 |
*
|
|
|
858 |
* @param \Illuminate\Support\Fluent $column
|
|
|
859 |
* @return string
|
|
|
860 |
*/
|
|
|
861 |
protected function typeUuid(Fluent $column)
|
|
|
862 |
{
|
|
|
863 |
return 'char(36)';
|
|
|
864 |
}
|
|
|
865 |
|
|
|
866 |
/**
|
|
|
867 |
* Create the column definition for an IP address type.
|
|
|
868 |
*
|
|
|
869 |
* @param \Illuminate\Support\Fluent $column
|
|
|
870 |
* @return string
|
|
|
871 |
*/
|
|
|
872 |
protected function typeIpAddress(Fluent $column)
|
|
|
873 |
{
|
|
|
874 |
return 'varchar(45)';
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
/**
|
|
|
878 |
* Create the column definition for a MAC address type.
|
|
|
879 |
*
|
|
|
880 |
* @param \Illuminate\Support\Fluent $column
|
|
|
881 |
* @return string
|
|
|
882 |
*/
|
|
|
883 |
protected function typeMacAddress(Fluent $column)
|
|
|
884 |
{
|
|
|
885 |
return 'varchar(17)';
|
|
|
886 |
}
|
|
|
887 |
|
|
|
888 |
/**
|
|
|
889 |
* Create the column definition for a spatial Geometry type.
|
|
|
890 |
*
|
|
|
891 |
* @param \Illuminate\Support\Fluent $column
|
|
|
892 |
* @return string
|
|
|
893 |
*/
|
|
|
894 |
public function typeGeometry(Fluent $column)
|
|
|
895 |
{
|
|
|
896 |
return 'geometry';
|
|
|
897 |
}
|
|
|
898 |
|
|
|
899 |
/**
|
|
|
900 |
* Create the column definition for a spatial Point type.
|
|
|
901 |
*
|
|
|
902 |
* @param \Illuminate\Support\Fluent $column
|
|
|
903 |
* @return string
|
|
|
904 |
*/
|
|
|
905 |
public function typePoint(Fluent $column)
|
|
|
906 |
{
|
|
|
907 |
return 'point';
|
|
|
908 |
}
|
|
|
909 |
|
|
|
910 |
/**
|
|
|
911 |
* Create the column definition for a spatial LineString type.
|
|
|
912 |
*
|
|
|
913 |
* @param \Illuminate\Support\Fluent $column
|
|
|
914 |
* @return string
|
|
|
915 |
*/
|
|
|
916 |
public function typeLineString(Fluent $column)
|
|
|
917 |
{
|
|
|
918 |
return 'linestring';
|
|
|
919 |
}
|
|
|
920 |
|
|
|
921 |
/**
|
|
|
922 |
* Create the column definition for a spatial Polygon type.
|
|
|
923 |
*
|
|
|
924 |
* @param \Illuminate\Support\Fluent $column
|
|
|
925 |
* @return string
|
|
|
926 |
*/
|
|
|
927 |
public function typePolygon(Fluent $column)
|
|
|
928 |
{
|
|
|
929 |
return 'polygon';
|
|
|
930 |
}
|
|
|
931 |
|
|
|
932 |
/**
|
|
|
933 |
* Create the column definition for a spatial GeometryCollection type.
|
|
|
934 |
*
|
|
|
935 |
* @param \Illuminate\Support\Fluent $column
|
|
|
936 |
* @return string
|
|
|
937 |
*/
|
|
|
938 |
public function typeGeometryCollection(Fluent $column)
|
|
|
939 |
{
|
|
|
940 |
return 'geometrycollection';
|
|
|
941 |
}
|
|
|
942 |
|
|
|
943 |
/**
|
|
|
944 |
* Create the column definition for a spatial MultiPoint type.
|
|
|
945 |
*
|
|
|
946 |
* @param \Illuminate\Support\Fluent $column
|
|
|
947 |
* @return string
|
|
|
948 |
*/
|
|
|
949 |
public function typeMultiPoint(Fluent $column)
|
|
|
950 |
{
|
|
|
951 |
return 'multipoint';
|
|
|
952 |
}
|
|
|
953 |
|
|
|
954 |
/**
|
|
|
955 |
* Create the column definition for a spatial MultiLineString type.
|
|
|
956 |
*
|
|
|
957 |
* @param \Illuminate\Support\Fluent $column
|
|
|
958 |
* @return string
|
|
|
959 |
*/
|
|
|
960 |
public function typeMultiLineString(Fluent $column)
|
|
|
961 |
{
|
|
|
962 |
return 'multilinestring';
|
|
|
963 |
}
|
|
|
964 |
|
|
|
965 |
/**
|
|
|
966 |
* Create the column definition for a spatial MultiPolygon type.
|
|
|
967 |
*
|
|
|
968 |
* @param \Illuminate\Support\Fluent $column
|
|
|
969 |
* @return string
|
|
|
970 |
*/
|
|
|
971 |
public function typeMultiPolygon(Fluent $column)
|
|
|
972 |
{
|
|
|
973 |
return 'multipolygon';
|
|
|
974 |
}
|
|
|
975 |
|
|
|
976 |
/**
|
|
|
977 |
* Create the column definition for a generated, computed column type.
|
|
|
978 |
*
|
|
|
979 |
* @param \Illuminate\Support\Fluent $column
|
|
|
980 |
* @return void
|
|
|
981 |
*
|
|
|
982 |
* @throws \RuntimeException
|
|
|
983 |
*/
|
|
|
984 |
protected function typeComputed(Fluent $column)
|
|
|
985 |
{
|
|
|
986 |
throw new RuntimeException('This database driver requires a type, see the virtualAs / storedAs modifiers.');
|
|
|
987 |
}
|
|
|
988 |
|
|
|
989 |
/**
|
|
|
990 |
* Get the SQL for a generated virtual column modifier.
|
|
|
991 |
*
|
|
|
992 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
993 |
* @param \Illuminate\Support\Fluent $column
|
|
|
994 |
* @return string|null
|
|
|
995 |
*/
|
|
|
996 |
protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
|
|
|
997 |
{
|
|
|
998 |
if (! is_null($virtualAs = $column->virtualAsJson)) {
|
|
|
999 |
if ($this->isJsonSelector($virtualAs)) {
|
|
|
1000 |
$virtualAs = $this->wrapJsonSelector($virtualAs);
|
|
|
1001 |
}
|
|
|
1002 |
|
|
|
1003 |
return " as ({$virtualAs})";
|
|
|
1004 |
}
|
|
|
1005 |
|
|
|
1006 |
if (! is_null($virtualAs = $column->virtualAs)) {
|
|
|
1007 |
return " as ({$virtualAs})";
|
|
|
1008 |
}
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
/**
|
|
|
1012 |
* Get the SQL for a generated stored column modifier.
|
|
|
1013 |
*
|
|
|
1014 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1015 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1016 |
* @return string|null
|
|
|
1017 |
*/
|
|
|
1018 |
protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
|
|
|
1019 |
{
|
|
|
1020 |
if (! is_null($storedAs = $column->storedAsJson)) {
|
|
|
1021 |
if ($this->isJsonSelector($storedAs)) {
|
|
|
1022 |
$storedAs = $this->wrapJsonSelector($storedAs);
|
|
|
1023 |
}
|
|
|
1024 |
|
|
|
1025 |
return " as ({$storedAs}) stored";
|
|
|
1026 |
}
|
|
|
1027 |
|
|
|
1028 |
if (! is_null($storedAs = $column->storedAs)) {
|
|
|
1029 |
return " as ({$storedAs}) stored";
|
|
|
1030 |
}
|
|
|
1031 |
}
|
|
|
1032 |
|
|
|
1033 |
/**
|
|
|
1034 |
* Get the SQL for an unsigned column modifier.
|
|
|
1035 |
*
|
|
|
1036 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1037 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1038 |
* @return string|null
|
|
|
1039 |
*/
|
|
|
1040 |
protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
|
|
|
1041 |
{
|
|
|
1042 |
if ($column->unsigned) {
|
|
|
1043 |
return ' unsigned';
|
|
|
1044 |
}
|
|
|
1045 |
}
|
|
|
1046 |
|
|
|
1047 |
/**
|
|
|
1048 |
* Get the SQL for a character set column modifier.
|
|
|
1049 |
*
|
|
|
1050 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1051 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1052 |
* @return string|null
|
|
|
1053 |
*/
|
|
|
1054 |
protected function modifyCharset(Blueprint $blueprint, Fluent $column)
|
|
|
1055 |
{
|
|
|
1056 |
if (! is_null($column->charset)) {
|
|
|
1057 |
return ' character set '.$column->charset;
|
|
|
1058 |
}
|
|
|
1059 |
}
|
|
|
1060 |
|
|
|
1061 |
/**
|
|
|
1062 |
* Get the SQL for a collation column modifier.
|
|
|
1063 |
*
|
|
|
1064 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1065 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1066 |
* @return string|null
|
|
|
1067 |
*/
|
|
|
1068 |
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
|
|
|
1069 |
{
|
|
|
1070 |
if (! is_null($column->collation)) {
|
|
|
1071 |
return " collate '{$column->collation}'";
|
|
|
1072 |
}
|
|
|
1073 |
}
|
|
|
1074 |
|
|
|
1075 |
/**
|
|
|
1076 |
* Get the SQL for a nullable column modifier.
|
|
|
1077 |
*
|
|
|
1078 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1079 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1080 |
* @return string|null
|
|
|
1081 |
*/
|
|
|
1082 |
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
|
|
1083 |
{
|
|
|
1084 |
if (is_null($column->virtualAs) &&
|
|
|
1085 |
is_null($column->virtualAsJson) &&
|
|
|
1086 |
is_null($column->storedAs) &&
|
|
|
1087 |
is_null($column->storedAsJson)) {
|
|
|
1088 |
return $column->nullable ? ' null' : ' not null';
|
|
|
1089 |
}
|
|
|
1090 |
|
|
|
1091 |
if ($column->nullable === false) {
|
|
|
1092 |
return ' not null';
|
|
|
1093 |
}
|
|
|
1094 |
}
|
|
|
1095 |
|
|
|
1096 |
/**
|
|
|
1097 |
* Get the SQL for an invisible column modifier.
|
|
|
1098 |
*
|
|
|
1099 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1100 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1101 |
* @return string|null
|
|
|
1102 |
*/
|
|
|
1103 |
protected function modifyInvisible(Blueprint $blueprint, Fluent $column)
|
|
|
1104 |
{
|
|
|
1105 |
if (! is_null($column->invisible)) {
|
|
|
1106 |
return ' invisible';
|
|
|
1107 |
}
|
|
|
1108 |
}
|
|
|
1109 |
|
|
|
1110 |
/**
|
|
|
1111 |
* Get the SQL for a default column modifier.
|
|
|
1112 |
*
|
|
|
1113 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1114 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1115 |
* @return string|null
|
|
|
1116 |
*/
|
|
|
1117 |
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
|
|
1118 |
{
|
|
|
1119 |
if (! is_null($column->default)) {
|
|
|
1120 |
return ' default '.$this->getDefaultValue($column->default);
|
|
|
1121 |
}
|
|
|
1122 |
}
|
|
|
1123 |
|
|
|
1124 |
/**
|
|
|
1125 |
* Get the SQL for an auto-increment column modifier.
|
|
|
1126 |
*
|
|
|
1127 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1128 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1129 |
* @return string|null
|
|
|
1130 |
*/
|
|
|
1131 |
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
|
|
|
1132 |
{
|
|
|
1133 |
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
|
|
|
1134 |
return ' auto_increment primary key';
|
|
|
1135 |
}
|
|
|
1136 |
}
|
|
|
1137 |
|
|
|
1138 |
/**
|
|
|
1139 |
* Get the SQL for a "first" column modifier.
|
|
|
1140 |
*
|
|
|
1141 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1142 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1143 |
* @return string|null
|
|
|
1144 |
*/
|
|
|
1145 |
protected function modifyFirst(Blueprint $blueprint, Fluent $column)
|
|
|
1146 |
{
|
|
|
1147 |
if (! is_null($column->first)) {
|
|
|
1148 |
return ' first';
|
|
|
1149 |
}
|
|
|
1150 |
}
|
|
|
1151 |
|
|
|
1152 |
/**
|
|
|
1153 |
* Get the SQL for an "after" column modifier.
|
|
|
1154 |
*
|
|
|
1155 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1156 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1157 |
* @return string|null
|
|
|
1158 |
*/
|
|
|
1159 |
protected function modifyAfter(Blueprint $blueprint, Fluent $column)
|
|
|
1160 |
{
|
|
|
1161 |
if (! is_null($column->after)) {
|
|
|
1162 |
return ' after '.$this->wrap($column->after);
|
|
|
1163 |
}
|
|
|
1164 |
}
|
|
|
1165 |
|
|
|
1166 |
/**
|
|
|
1167 |
* Get the SQL for a "comment" column modifier.
|
|
|
1168 |
*
|
|
|
1169 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1170 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1171 |
* @return string|null
|
|
|
1172 |
*/
|
|
|
1173 |
protected function modifyComment(Blueprint $blueprint, Fluent $column)
|
|
|
1174 |
{
|
|
|
1175 |
if (! is_null($column->comment)) {
|
|
|
1176 |
return " comment '".addslashes($column->comment)."'";
|
|
|
1177 |
}
|
|
|
1178 |
}
|
|
|
1179 |
|
|
|
1180 |
/**
|
|
|
1181 |
* Get the SQL for a SRID column modifier.
|
|
|
1182 |
*
|
|
|
1183 |
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
|
|
1184 |
* @param \Illuminate\Support\Fluent $column
|
|
|
1185 |
* @return string|null
|
|
|
1186 |
*/
|
|
|
1187 |
protected function modifySrid(Blueprint $blueprint, Fluent $column)
|
|
|
1188 |
{
|
|
|
1189 |
if (is_int($column->srid) && $column->srid > 0) {
|
|
|
1190 |
return ' srid '.$column->srid;
|
|
|
1191 |
}
|
|
|
1192 |
}
|
|
|
1193 |
|
|
|
1194 |
/**
|
|
|
1195 |
* Wrap a single string in keyword identifiers.
|
|
|
1196 |
*
|
|
|
1197 |
* @param string $value
|
|
|
1198 |
* @return string
|
|
|
1199 |
*/
|
|
|
1200 |
protected function wrapValue($value)
|
|
|
1201 |
{
|
|
|
1202 |
if ($value !== '*') {
|
|
|
1203 |
return '`'.str_replace('`', '``', $value).'`';
|
|
|
1204 |
}
|
|
|
1205 |
|
|
|
1206 |
return $value;
|
|
|
1207 |
}
|
|
|
1208 |
|
|
|
1209 |
/**
|
|
|
1210 |
* Wrap the given JSON selector.
|
|
|
1211 |
*
|
|
|
1212 |
* @param string $value
|
|
|
1213 |
* @return string
|
|
|
1214 |
*/
|
|
|
1215 |
protected function wrapJsonSelector($value)
|
|
|
1216 |
{
|
|
|
1217 |
[$field, $path] = $this->wrapJsonFieldAndPath($value);
|
|
|
1218 |
|
|
|
1219 |
return 'json_unquote(json_extract('.$field.$path.'))';
|
|
|
1220 |
}
|
|
|
1221 |
}
|