1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Oci8\Schema\Grammars; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Support\Fluent; |
7
|
|
|
use Illuminate\Database\Connection; |
8
|
|
|
use Yajra\Oci8\OracleReservedWords; |
9
|
|
|
use Illuminate\Database\Schema\Blueprint; |
10
|
|
|
use Illuminate\Database\Schema\Grammars\Grammar; |
11
|
|
|
|
12
|
|
|
class OracleGrammar extends Grammar |
13
|
|
|
{ |
14
|
|
|
use OracleReservedWords; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The keyword identifier wrapper format. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $wrapper = '%s'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The possible column modifiers. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $modifiers = ['Increment', 'Nullable', 'Default']; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The possible column serials. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger']; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $schema_prefix = ''; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* If this Grammar supports schema changes wrapped in a transaction. |
44
|
|
|
* |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
protected $transactions = true; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Compile a create table command. |
51
|
|
|
* |
52
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
53
|
|
|
* @param \Illuminate\Support\Fluent $command |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
30 |
|
public function compileCreate(Blueprint $blueprint, Fluent $command) |
57
|
|
|
{ |
58
|
30 |
|
$columns = implode(', ', $this->getColumns($blueprint)); |
59
|
|
|
|
60
|
30 |
|
$sql = 'create table ' . $this->wrapTable($blueprint) . " ( $columns"; |
61
|
|
|
|
62
|
|
|
/* |
63
|
|
|
* To be able to name the primary/foreign keys when the table is |
64
|
|
|
* initially created we will need to check for a primary/foreign |
65
|
|
|
* key commands and add the columns to the table's declaration |
66
|
|
|
* here so they can be created on the tables. |
67
|
|
|
*/ |
68
|
30 |
|
$sql .= (string) $this->addForeignKeys($blueprint); |
69
|
|
|
|
70
|
30 |
|
$sql .= (string) $this->addPrimaryKeys($blueprint); |
71
|
|
|
|
72
|
30 |
|
$sql .= ' )'; |
73
|
|
|
|
74
|
30 |
|
return $sql; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Wrap a table in keyword identifiers. |
79
|
|
|
* |
80
|
|
|
* @param mixed $table |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
177 |
|
public function wrapTable($table) |
84
|
|
|
{ |
85
|
177 |
|
return $this->getSchemaPrefix() . parent::wrapTable($table); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the schema prefix. |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
177 |
|
public function getSchemaPrefix() |
94
|
|
|
{ |
95
|
177 |
|
return ! empty($this->schema_prefix) ? $this->schema_prefix . '.' : ''; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Set the schema prefix. |
100
|
|
|
* |
101
|
|
|
* @param string $prefix |
102
|
|
|
*/ |
103
|
|
|
public function setSchemaPrefix($prefix) |
104
|
|
|
{ |
105
|
|
|
$this->schema_prefix = $prefix; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get the foreign key syntax for a table creation statement. |
110
|
|
|
* |
111
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
30 |
|
protected function addForeignKeys(Blueprint $blueprint) |
115
|
|
|
{ |
116
|
30 |
|
$sql = ''; |
117
|
|
|
|
118
|
30 |
|
$foreigns = $this->getCommandsByName($blueprint, 'foreign'); |
119
|
|
|
|
120
|
|
|
// Once we have all the foreign key commands for the table creation statement |
121
|
|
|
// we'll loop through each of them and add them to the create table SQL we |
122
|
|
|
// are building |
123
|
30 |
|
foreach ($foreigns as $foreign) { |
124
|
9 |
|
$on = $this->wrapTable($foreign->on); |
125
|
|
|
|
126
|
9 |
|
$columns = $this->columnize($foreign->columns); |
127
|
|
|
|
128
|
9 |
|
$onColumns = $this->columnize((array) $foreign->references); |
129
|
|
|
|
130
|
9 |
|
$sql .= ", constraint {$foreign->index} foreign key ( {$columns} ) references {$on} ( {$onColumns} )"; |
131
|
|
|
|
132
|
|
|
// Once we have the basic foreign key creation statement constructed we can |
133
|
|
|
// build out the syntax for what should happen on an update or delete of |
134
|
|
|
// the affected columns, which will get something like "cascade", etc. |
135
|
9 |
|
if (! is_null($foreign->onDelete)) { |
136
|
5 |
|
$sql .= " on delete {$foreign->onDelete}"; |
137
|
2 |
|
} |
138
|
20 |
|
} |
139
|
|
|
|
140
|
30 |
|
return $sql; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the primary key syntax for a table creation statement. |
145
|
|
|
* |
146
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
147
|
|
|
* @return string|null |
148
|
|
|
*/ |
149
|
120 |
|
protected function addPrimaryKeys(Blueprint $blueprint) |
150
|
|
|
{ |
151
|
120 |
|
$primary = $this->getCommandByName($blueprint, 'primary'); |
152
|
|
|
|
153
|
120 |
|
if (! is_null($primary)) { |
154
|
51 |
|
$columns = $this->columnize($primary->columns); |
155
|
|
|
|
156
|
51 |
|
return ", constraint {$primary->index} primary key ( {$columns} )"; |
157
|
|
|
} |
158
|
|
|
|
159
|
75 |
|
return ''; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Compile the query to determine if a table exists. |
164
|
|
|
* |
165
|
|
|
* @return string |
166
|
|
|
*/ |
167
|
3 |
|
public function compileTableExists() |
168
|
|
|
{ |
169
|
3 |
|
return 'select * from all_tables where upper(owner) = upper(?) and upper(table_name) = upper(?)'; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Compile the query to determine the list of columns. |
174
|
|
|
* |
175
|
|
|
* @param string $database |
176
|
|
|
* @param string $table |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
3 |
|
public function compileColumnExists($database, $table) |
180
|
|
|
{ |
181
|
3 |
|
return "select column_name from all_tab_cols where upper(owner) = upper('{$database}') and upper(table_name) = upper('{$table}')"; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Compile an add column command. |
186
|
|
|
* |
187
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
188
|
|
|
* @param \Illuminate\Support\Fluent $command |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
90 |
|
public function compileAdd(Blueprint $blueprint, Fluent $command) |
192
|
|
|
{ |
193
|
90 |
|
$columns = implode(', ', $this->getColumns($blueprint)); |
194
|
|
|
|
195
|
90 |
|
$sql = 'alter table ' . $this->wrapTable($blueprint) . " add ( $columns"; |
196
|
|
|
|
197
|
90 |
|
$sql .= (string) $this->addPrimaryKeys($blueprint); |
198
|
|
|
|
199
|
90 |
|
return $sql .= ' )'; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Compile a primary key command. |
204
|
|
|
* |
205
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
206
|
|
|
* @param \Illuminate\Support\Fluent $command |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
27 |
|
public function compilePrimary(Blueprint $blueprint, Fluent $command) |
210
|
|
|
{ |
211
|
27 |
|
$create = $this->getCommandByName($blueprint, 'create'); |
212
|
|
|
|
213
|
27 |
|
if (is_null($create)) { |
214
|
9 |
|
$columns = $this->columnize($command->columns); |
215
|
|
|
|
216
|
9 |
|
$table = $this->wrapTable($blueprint); |
217
|
|
|
|
218
|
9 |
|
return "alter table {$table} add constraint {$command->index} primary key ({$columns})"; |
219
|
|
|
} |
220
|
18 |
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Compile a foreign key command. |
224
|
|
|
* |
225
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
226
|
|
|
* @param \Illuminate\Support\Fluent $command |
227
|
|
|
* @return string|void |
228
|
|
|
*/ |
229
|
15 |
|
public function compileForeign(Blueprint $blueprint, Fluent $command) |
230
|
|
|
{ |
231
|
15 |
|
$create = $this->getCommandByName($blueprint, 'create'); |
232
|
|
|
|
233
|
15 |
|
if (is_null($create)) { |
234
|
6 |
|
$table = $this->wrapTable($blueprint); |
235
|
|
|
|
236
|
6 |
|
$on = $this->wrapTable($command->on); |
237
|
|
|
|
238
|
|
|
// We need to prepare several of the elements of the foreign key definition |
239
|
|
|
// before we can create the SQL, such as wrapping the tables and convert |
240
|
|
|
// an array of columns to comma-delimited strings for the SQL queries. |
241
|
6 |
|
$columns = $this->columnize($command->columns); |
242
|
|
|
|
243
|
6 |
|
$onColumns = $this->columnize((array) $command->references); |
244
|
|
|
|
245
|
6 |
|
$sql = "alter table {$table} add constraint {$command->index} "; |
246
|
|
|
|
247
|
6 |
|
$sql .= "foreign key ( {$columns} ) references {$on} ( {$onColumns} )"; |
248
|
|
|
|
249
|
|
|
// Once we have the basic foreign key creation statement constructed we can |
250
|
|
|
// build out the syntax for what should happen on an update or delete of |
251
|
|
|
// the affected columns, which will get something like "cascade", etc. |
252
|
6 |
|
if (! is_null($command->onDelete)) { |
253
|
3 |
|
$sql .= " on delete {$command->onDelete}"; |
254
|
2 |
|
} |
255
|
|
|
|
256
|
6 |
|
return $sql; |
257
|
|
|
} |
258
|
9 |
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Compile a unique key command. |
262
|
|
|
* |
263
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
264
|
|
|
* @param \Illuminate\Support\Fluent $command |
265
|
|
|
* @return string |
266
|
|
|
*/ |
267
|
9 |
|
public function compileUnique(Blueprint $blueprint, Fluent $command) |
268
|
|
|
{ |
269
|
9 |
|
return 'alter table ' . $this->wrapTable($blueprint) . " add constraint {$command->index} unique ( " . $this->columnize($command->columns) . ' )'; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Compile a plain index key command. |
274
|
|
|
* |
275
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
276
|
|
|
* @param \Illuminate\Support\Fluent $command |
277
|
|
|
* @return string |
278
|
|
|
*/ |
279
|
3 |
|
public function compileIndex(Blueprint $blueprint, Fluent $command) |
280
|
|
|
{ |
281
|
3 |
|
return "create index {$command->index} on " . $this->wrapTable($blueprint) . ' ( ' . $this->columnize($command->columns) . ' )'; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Compile a drop table command. |
286
|
|
|
* |
287
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
288
|
|
|
* @param \Illuminate\Support\Fluent $command |
289
|
|
|
* @return string |
290
|
|
|
*/ |
291
|
6 |
|
public function compileDrop(Blueprint $blueprint, Fluent $command) |
292
|
|
|
{ |
293
|
6 |
|
return 'drop table ' . $this->wrapTable($blueprint); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Compile the SQL needed to drop all tables. |
298
|
|
|
* |
299
|
|
|
* @return string |
300
|
|
|
*/ |
301
|
|
|
public function compileDropAllTables() |
302
|
|
|
{ |
303
|
|
|
return 'BEGIN |
304
|
|
|
FOR c IN (SELECT table_name FROM user_tables) LOOP |
305
|
|
|
EXECUTE IMMEDIATE (\'DROP TABLE "\' || c.table_name || \'" CASCADE CONSTRAINTS\'); |
306
|
|
|
END LOOP; |
307
|
|
|
|
308
|
|
|
FOR s IN (SELECT sequence_name FROM user_sequences) LOOP |
309
|
|
|
EXECUTE IMMEDIATE (\'DROP SEQUENCE \' || s.sequence_name); |
310
|
|
|
END LOOP; |
311
|
|
|
|
312
|
|
|
END;'; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Compile a drop table (if exists) command. |
317
|
|
|
* |
318
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
319
|
|
|
* @param \Illuminate\Support\Fluent $command |
320
|
|
|
* @return string |
321
|
|
|
*/ |
322
|
|
|
public function compileDropIfExists(Blueprint $blueprint, Fluent $command) |
323
|
6 |
|
{ |
324
|
|
|
$table = $this->wrapTable($blueprint); |
325
|
6 |
|
|
326
|
|
|
return "declare c int; |
327
|
6 |
|
begin |
328
|
|
|
select count(*) into c from user_tables where table_name = upper('$table'); |
329
|
6 |
|
if c = 1 then |
330
|
|
|
execute immediate 'drop table $table'; |
331
|
|
|
end if; |
332
|
|
|
end;"; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Compile a drop column command. |
337
|
|
|
* |
338
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
339
|
3 |
|
* @param \Illuminate\Support\Fluent $command |
340
|
|
|
* @return string |
341
|
3 |
|
*/ |
342
|
|
|
public function compileDropColumn(Blueprint $blueprint, Fluent $command) |
343
|
|
|
{ |
344
|
|
|
$columns = $this->wrapArray($command->columns); |
345
|
|
|
|
346
|
|
|
$table = $this->wrapTable($blueprint); |
347
|
|
|
|
348
|
|
|
return 'alter table ' . $table . ' drop ( ' . implode(', ', $columns) . ' )'; |
349
|
|
|
} |
350
|
12 |
|
|
351
|
|
|
/** |
352
|
12 |
|
* Compile a drop primary key command. |
353
|
12 |
|
* |
354
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
355
|
12 |
|
* @param \Illuminate\Support\Fluent $command |
356
|
3 |
|
* @return string |
357
|
|
|
*/ |
358
|
|
|
public function compileDropPrimary(Blueprint $blueprint, Fluent $command) |
359
|
9 |
|
{ |
360
|
|
|
return $this->dropConstraint($blueprint, $command, 'primary'); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @param Blueprint $blueprint |
365
|
|
|
* @param Fluent $command |
366
|
|
|
* @param string $type |
367
|
|
|
* @return string |
368
|
|
|
*/ |
369
|
3 |
|
private function dropConstraint(Blueprint $blueprint, Fluent $command, $type) |
370
|
|
|
{ |
371
|
3 |
|
$table = $this->wrapTable($blueprint); |
372
|
|
|
$index = substr($command->index, 0, 30); |
373
|
|
|
|
374
|
|
|
if ($type === 'index') { |
375
|
|
|
return "drop index {$index}"; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
return "alter table {$table} drop constraint {$index}"; |
379
|
|
|
} |
380
|
|
|
|
381
|
3 |
|
/** |
382
|
|
|
* Compile a drop unique key command. |
383
|
3 |
|
* |
384
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
385
|
|
|
* @param \Illuminate\Support\Fluent $command |
386
|
|
|
* @return string |
387
|
|
|
*/ |
388
|
|
|
public function compileDropUnique(Blueprint $blueprint, Fluent $command) |
389
|
|
|
{ |
390
|
|
|
return $this->dropConstraint($blueprint, $command, 'unique'); |
391
|
|
|
} |
392
|
|
|
|
393
|
3 |
|
/** |
394
|
|
|
* Compile a drop index command. |
395
|
3 |
|
* |
396
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
397
|
|
|
* @param \Illuminate\Support\Fluent $command |
398
|
|
|
* @return string |
399
|
|
|
*/ |
400
|
|
|
public function compileDropIndex(Blueprint $blueprint, Fluent $command) |
401
|
|
|
{ |
402
|
|
|
return $this->dropConstraint($blueprint, $command, 'index'); |
403
|
|
|
} |
404
|
|
|
|
405
|
6 |
|
/** |
406
|
|
|
* Compile a drop foreign key command. |
407
|
6 |
|
* |
408
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
409
|
6 |
|
* @param \Illuminate\Support\Fluent $command |
410
|
|
|
* @return string |
411
|
|
|
*/ |
412
|
|
|
public function compileDropForeign(Blueprint $blueprint, Fluent $command) |
413
|
|
|
{ |
414
|
|
|
return $this->dropConstraint($blueprint, $command, 'foreign'); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Compile a rename table command. |
419
|
|
|
* |
420
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
421
|
|
|
* @param \Illuminate\Support\Fluent $command |
422
|
|
|
* @return string |
423
|
|
|
*/ |
424
|
|
|
public function compileRename(Blueprint $blueprint, Fluent $command) |
425
|
|
|
{ |
426
|
|
|
$from = $this->wrapTable($blueprint); |
427
|
|
|
|
428
|
|
|
return "alter table {$from} rename to " . $this->wrapTable($command->to); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Compile a rename column command. |
433
|
|
|
* |
434
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
435
|
|
|
* @param \Illuminate\Support\Fluent $command |
436
|
3 |
|
* @param \Illuminate\Database\Connection $connection |
437
|
|
|
* @return array |
438
|
3 |
|
*/ |
439
|
|
|
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection) |
440
|
|
|
{ |
441
|
|
|
$table = $this->wrapTable($blueprint); |
442
|
|
|
|
443
|
|
|
$rs = []; |
444
|
|
|
$rs[0] = 'alter table ' . $table . ' rename column ' . $command->from . ' to ' . $command->to; |
445
|
|
|
|
446
|
|
|
return (array) $rs; |
447
|
42 |
|
} |
448
|
|
|
|
449
|
42 |
|
/** |
450
|
|
|
* Create the column definition for a char type. |
451
|
|
|
* |
452
|
|
|
* @param \Illuminate\Support\Fluent $column |
453
|
|
|
* @return string |
454
|
|
|
*/ |
455
|
|
|
protected function typeChar(Fluent $column) |
456
|
|
|
{ |
457
|
|
|
return "char({$column->length})"; |
458
|
3 |
|
} |
459
|
|
|
|
460
|
3 |
|
/** |
461
|
|
|
* Create the column definition for a string type. |
462
|
|
|
* |
463
|
|
|
* @param \Illuminate\Support\Fluent $column |
464
|
|
|
* @return string |
465
|
|
|
*/ |
466
|
|
|
protected function typeString(Fluent $column) |
467
|
|
|
{ |
468
|
|
|
return "varchar2({$column->length})"; |
469
|
3 |
|
} |
470
|
|
|
|
471
|
3 |
|
/** |
472
|
|
|
* Create column definition for a nvarchar type. |
473
|
|
|
* |
474
|
|
|
* @param \Illuminate\Support\Fluent $column |
475
|
|
|
* @return string |
476
|
|
|
*/ |
477
|
|
|
protected function typeNvarchar2(Fluent $column) |
478
|
|
|
{ |
479
|
|
|
return "nvarchar2({$column->length})"; |
480
|
3 |
|
} |
481
|
|
|
|
482
|
3 |
|
/** |
483
|
|
|
* Create the column definition for a text type. |
484
|
|
|
* |
485
|
|
|
* @param \Illuminate\Support\Fluent $column |
486
|
|
|
* @return string |
487
|
|
|
*/ |
488
|
|
|
protected function typeText(Fluent $column) |
489
|
|
|
{ |
490
|
|
|
return 'clob'; |
491
|
3 |
|
} |
492
|
|
|
|
493
|
3 |
|
/** |
494
|
|
|
* Create the column definition for a medium text type. |
495
|
|
|
* |
496
|
|
|
* @param \Illuminate\Support\Fluent $column |
497
|
|
|
* @return string |
498
|
|
|
*/ |
499
|
|
|
protected function typeMediumText(Fluent $column) |
500
|
|
|
{ |
501
|
|
|
return 'clob'; |
502
|
48 |
|
} |
503
|
|
|
|
504
|
48 |
|
/** |
505
|
|
|
* Create the column definition for a long text type. |
506
|
48 |
|
* |
507
|
|
|
* @param \Illuminate\Support\Fluent $column |
508
|
|
|
* @return string |
509
|
|
|
*/ |
510
|
|
|
protected function typeLongText(Fluent $column) |
511
|
|
|
{ |
512
|
|
|
return 'clob'; |
513
|
|
|
} |
514
|
|
|
|
515
|
3 |
|
/** |
516
|
|
|
* Create the column definition for a integer type. |
517
|
3 |
|
* |
518
|
|
|
* @param \Illuminate\Support\Fluent $column |
519
|
3 |
|
* @return string |
520
|
|
|
*/ |
521
|
|
|
protected function typeInteger(Fluent $column) |
522
|
|
|
{ |
523
|
|
|
$length = ($column->length) ? $column->length : 10; |
524
|
|
|
|
525
|
|
|
return "number({$length},0)"; |
526
|
|
|
} |
527
|
|
|
|
528
|
3 |
|
/** |
529
|
|
|
* Create the column definition for a integer type. |
530
|
3 |
|
* |
531
|
|
|
* @param \Illuminate\Support\Fluent $column |
532
|
3 |
|
* @return string |
533
|
|
|
*/ |
534
|
|
|
protected function typeBigInteger(Fluent $column) |
535
|
|
|
{ |
536
|
|
|
$length = ($column->length) ? $column->length : 19; |
537
|
|
|
|
538
|
|
|
return "number({$length},0)"; |
539
|
|
|
} |
540
|
|
|
|
541
|
3 |
|
/** |
542
|
|
|
* Create the column definition for a medium integer type. |
543
|
3 |
|
* |
544
|
|
|
* @param \Illuminate\Support\Fluent $column |
545
|
3 |
|
* @return string |
546
|
|
|
*/ |
547
|
|
|
protected function typeMediumInteger(Fluent $column) |
548
|
|
|
{ |
549
|
|
|
$length = ($column->length) ? $column->length : 7; |
550
|
|
|
|
551
|
|
|
return "number({$length},0)"; |
552
|
|
|
} |
553
|
|
|
|
554
|
3 |
|
/** |
555
|
|
|
* Create the column definition for a small integer type. |
556
|
3 |
|
* |
557
|
|
|
* @param \Illuminate\Support\Fluent $column |
558
|
3 |
|
* @return string |
559
|
|
|
*/ |
560
|
|
|
protected function typeSmallInteger(Fluent $column) |
561
|
|
|
{ |
562
|
|
|
$length = ($column->length) ? $column->length : 5; |
563
|
|
|
|
564
|
|
|
return "number({$length},0)"; |
565
|
|
|
} |
566
|
|
|
|
567
|
3 |
|
/** |
568
|
|
|
* Create the column definition for a tiny integer type. |
569
|
3 |
|
* |
570
|
|
|
* @param \Illuminate\Support\Fluent $column |
571
|
|
|
* @return string |
572
|
|
|
*/ |
573
|
|
|
protected function typeTinyInteger(Fluent $column) |
574
|
|
|
{ |
575
|
|
|
$length = ($column->length) ? $column->length : 3; |
576
|
|
|
|
577
|
|
|
return "number({$length},0)"; |
578
|
3 |
|
} |
579
|
|
|
|
580
|
3 |
|
/** |
581
|
|
|
* Create the column definition for a float type. |
582
|
|
|
* |
583
|
|
|
* @param \Illuminate\Support\Fluent $column |
584
|
|
|
* @return string |
585
|
|
|
*/ |
586
|
|
|
protected function typeFloat(Fluent $column) |
587
|
|
|
{ |
588
|
|
|
return "number({$column->total}, {$column->places})"; |
589
|
3 |
|
} |
590
|
|
|
|
591
|
3 |
|
/** |
592
|
|
|
* Create the column definition for a double type. |
593
|
|
|
* |
594
|
|
|
* @param \Illuminate\Support\Fluent $column |
595
|
|
|
* @return string |
596
|
|
|
*/ |
597
|
|
|
protected function typeDouble(Fluent $column) |
598
|
|
|
{ |
599
|
|
|
return "number({$column->total}, {$column->places})"; |
600
|
3 |
|
} |
601
|
|
|
|
602
|
3 |
|
/** |
603
|
|
|
* Create the column definition for a decimal type. |
604
|
|
|
* |
605
|
|
|
* @param \Illuminate\Support\Fluent $column |
606
|
|
|
* @return string |
607
|
|
|
*/ |
608
|
|
|
protected function typeDecimal(Fluent $column) |
609
|
|
|
{ |
610
|
|
|
return "number({$column->total}, {$column->places})"; |
611
|
6 |
|
} |
612
|
|
|
|
613
|
6 |
|
/** |
614
|
|
|
* Create the column definition for a boolean type. |
615
|
6 |
|
* |
616
|
|
|
* @param \Illuminate\Support\Fluent $column |
617
|
|
|
* @return string |
618
|
|
|
*/ |
619
|
|
|
protected function typeBoolean(Fluent $column) |
620
|
|
|
{ |
621
|
|
|
return 'char(1)'; |
622
|
|
|
} |
623
|
|
|
|
624
|
3 |
|
/** |
625
|
|
|
* Create the column definition for a enum type. |
626
|
3 |
|
* |
627
|
|
|
* @param \Illuminate\Support\Fluent $column |
628
|
|
|
* @return string |
629
|
|
|
*/ |
630
|
|
|
protected function typeEnum(Fluent $column) |
631
|
|
|
{ |
632
|
|
|
$length = ($column->length) ? $column->length : 255; |
633
|
|
|
|
634
|
|
|
return "varchar2({$length})"; |
635
|
3 |
|
} |
636
|
|
|
|
637
|
3 |
|
/** |
638
|
|
|
* Create the column definition for a date type. |
639
|
|
|
* |
640
|
|
|
* @param \Illuminate\Support\Fluent $column |
641
|
|
|
* @return string |
642
|
|
|
*/ |
643
|
|
|
protected function typeDate(Fluent $column) |
644
|
|
|
{ |
645
|
|
|
return 'date'; |
646
|
3 |
|
} |
647
|
|
|
|
648
|
3 |
|
/** |
649
|
|
|
* Create the column definition for a date-time type. |
650
|
|
|
* |
651
|
|
|
* @param \Illuminate\Support\Fluent $column |
652
|
|
|
* @return string |
653
|
|
|
*/ |
654
|
|
|
protected function typeDateTime(Fluent $column) |
655
|
|
|
{ |
656
|
|
|
return 'date'; |
657
|
9 |
|
} |
658
|
|
|
|
659
|
9 |
|
/** |
660
|
|
|
* Create the column definition for a time type. |
661
|
|
|
* |
662
|
|
|
* @param \Illuminate\Support\Fluent $column |
663
|
|
|
* @return string |
664
|
|
|
*/ |
665
|
|
|
protected function typeTime(Fluent $column) |
666
|
|
|
{ |
667
|
|
|
return 'date'; |
668
|
6 |
|
} |
669
|
|
|
|
670
|
6 |
|
/** |
671
|
|
|
* Create the column definition for a timestamp type. |
672
|
|
|
* |
673
|
|
|
* @param \Illuminate\Support\Fluent $column |
674
|
|
|
* @return string |
675
|
|
|
*/ |
676
|
|
|
protected function typeTimestamp(Fluent $column) |
677
|
|
|
{ |
678
|
|
|
return 'timestamp'; |
679
|
3 |
|
} |
680
|
|
|
|
681
|
3 |
|
/** |
682
|
|
|
* Create the column definition for a timestamp type with timezone. |
683
|
|
|
* |
684
|
|
|
* @param Fluent $column |
685
|
|
|
* @return string |
686
|
|
|
*/ |
687
|
|
|
protected function typeTimestampTz(Fluent $column) |
688
|
|
|
{ |
689
|
|
|
return 'timestamp with time zone'; |
690
|
|
|
} |
691
|
120 |
|
|
692
|
|
|
/** |
693
|
|
|
* Create the column definition for a binary type. |
694
|
120 |
|
* |
695
|
120 |
|
* @param \Illuminate\Support\Fluent $column |
696
|
6 |
|
* @return string |
697
|
4 |
|
*/ |
698
|
|
|
protected function typeBinary(Fluent $column) |
699
|
120 |
|
{ |
700
|
120 |
|
return 'blob'; |
701
|
|
|
} |
702
|
120 |
|
|
703
|
9 |
|
/** |
704
|
|
|
* Create the column definition for a uuid type. |
705
|
|
|
* |
706
|
117 |
|
* @param \Illuminate\Support\Fluent $column |
707
|
|
|
* @return string |
708
|
|
|
*/ |
709
|
|
|
protected function typeUuid(Fluent $column) |
710
|
|
|
{ |
711
|
|
|
return 'char(36)'; |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* Create the column definition for a json type. |
716
|
120 |
|
* |
717
|
|
|
* @param \Illuminate\Support\Fluent $column |
718
|
|
|
* @return string |
719
|
120 |
|
*/ |
720
|
|
|
protected function typeJson(Fluent $column) |
721
|
|
|
{ |
722
|
|
|
return 'clob'; |
723
|
|
|
} |
724
|
|
|
|
725
|
|
|
/** |
726
|
|
|
* Create the column definition for a jsonb type. |
727
|
|
|
* |
728
|
|
|
* @param \Illuminate\Support\Fluent $column |
729
|
120 |
|
* @return string |
730
|
|
|
*/ |
731
|
120 |
|
protected function typeJsonb(Fluent $column) |
732
|
33 |
|
{ |
733
|
22 |
|
return 'clob'; |
734
|
120 |
|
} |
735
|
|
|
|
736
|
|
|
/** |
737
|
|
|
* Get the SQL for a nullable column modifier. |
738
|
|
|
* |
739
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
740
|
|
|
* @param \Illuminate\Support\Fluent $column |
741
|
|
|
* @return string |
742
|
177 |
|
*/ |
743
|
|
|
protected function modifyNullable(Blueprint $blueprint, Fluent $column) |
744
|
177 |
|
{ |
745
|
3 |
|
// check if field is declared as enum |
746
|
|
|
$enum = ''; |
747
|
|
|
if (count((array) $column->allowed)) { |
748
|
177 |
|
$columnName = $this->wrapValue($column->name); |
749
|
|
|
$enum = " check ({$columnName} in ('" . implode("', '", $column->allowed) . "'))"; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
$null = $column->nullable ? ' null' : ' not null'; |
753
|
|
|
$null .= $enum; |
754
|
|
|
|
755
|
|
|
if (! is_null($column->default)) { |
756
|
|
|
return ' default ' . $this->getDefaultValue($column->default) . $null; |
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
return $null; |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
/** |
763
|
|
|
* Get the SQL for a default column modifier. |
764
|
|
|
* |
765
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
766
|
|
|
* @param \Illuminate\Support\Fluent $column |
767
|
|
|
* @return string |
768
|
|
|
*/ |
769
|
|
|
protected function modifyDefault(Blueprint $blueprint, Fluent $column) |
770
|
|
|
{ |
771
|
|
|
// implemented @modifyNullable |
772
|
|
|
return ''; |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
/** |
776
|
|
|
* Get the SQL for an auto-increment column modifier. |
777
|
|
|
* |
778
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint |
779
|
|
|
* @param \Illuminate\Support\Fluent $column |
780
|
|
|
* @return string|null |
781
|
|
|
*/ |
782
|
|
|
protected function modifyIncrement(Blueprint $blueprint, Fluent $column) |
783
|
|
|
{ |
784
|
|
|
if (in_array($column->type, $this->serials) && $column->autoIncrement) { |
785
|
|
|
$blueprint->primary($column->name); |
786
|
|
|
} |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
/** |
790
|
|
|
* Wrap a single string in keyword identifiers. |
791
|
|
|
* |
792
|
|
|
* @param string $value |
793
|
|
|
* @return string |
794
|
|
|
*/ |
795
|
|
|
protected function wrapValue($value) |
796
|
|
|
{ |
797
|
|
|
if ($this->isReserved($value)) { |
798
|
|
|
return Str::upper(parent::wrapValue($value)); |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
return $value !== '*' ? sprintf($this->wrapper, $value) : $value; |
802
|
|
|
} |
803
|
|
|
} |
804
|
|
|
|