1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Oci8\Schema; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
6
|
|
|
|
7
|
|
|
class OracleBlueprint extends Blueprint |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Table comment. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
public $comment = null; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Column comments. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
public $commentColumns = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Database prefix variable. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $prefix; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Set table prefix settings. |
32
|
|
|
* |
33
|
|
|
* @param string $prefix |
34
|
|
|
*/ |
35
|
24 |
|
public function setTablePrefix($prefix = '') |
36
|
|
|
{ |
37
|
24 |
|
$this->prefix = $prefix; |
38
|
24 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Create a default index name for the table. |
42
|
|
|
* |
43
|
|
|
* @param string $type |
44
|
|
|
* @param array $columns |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
66 |
|
protected function createIndexName($type, array $columns) |
48
|
|
|
{ |
49
|
|
|
$short_type = [ |
50
|
66 |
|
'primary' => 'pk', |
51
|
44 |
|
'foreign' => 'fk', |
52
|
44 |
|
'unique' => 'uk', |
53
|
44 |
|
]; |
54
|
|
|
|
55
|
66 |
|
$type = isset($short_type[$type]) ? $short_type[$type] : $type; |
56
|
|
|
|
57
|
66 |
|
$index = strtolower($this->prefix . $this->table . '_' . implode('_', $columns) . '_' . $type); |
58
|
|
|
|
59
|
|
|
$index = str_replace(['-', '.'], '_', $index); |
60
|
66 |
|
|
61
|
|
|
//shorten the name if it is longer than 30 chars |
62
|
|
|
while (strlen($index) > 30) { |
63
|
|
|
$parts = explode("_", $index); |
64
|
|
|
|
65
|
|
|
for($i = 0; $i < sizeof($parts);$i++) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
//if any part is longer than 2 chars, take one off |
68
|
|
|
$len = strlen($parts[$i]); |
69
|
|
|
if ($len > 2) { |
70
|
3 |
|
$parts[$i] = substr($parts[$i], 0, $len - 1); |
71
|
|
|
} |
72
|
3 |
|
} |
73
|
|
|
|
74
|
|
|
$index = implode('_', $parts); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $index; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Create a new nvarchar2 column on the table. |
82
|
|
|
* |
83
|
|
|
* @param string $column |
84
|
|
|
* @param int $length |
85
|
|
|
* @return \Illuminate\Support\Fluent |
86
|
|
|
*/ |
87
|
|
|
public function nvarchar2($column, $length = 255) |
88
|
|
|
{ |
89
|
|
|
return $this->addColumn('nvarchar2', $column, compact('length')); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: