1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Oci8\Schema; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Connection; |
6
|
|
|
use Illuminate\Database\Schema\Grammars\Grammar; |
7
|
|
|
use Yajra\Oci8\OracleReservedWords; |
8
|
|
|
|
9
|
|
|
class Comment extends Grammar |
10
|
|
|
{ |
11
|
|
|
use OracleReservedWords; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var \Illuminate\Database\Connection |
15
|
|
|
*/ |
16
|
|
|
protected $connection; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param Connection $connection |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Connection $connection) |
22
|
|
|
{ |
23
|
|
|
$this->connection = $connection; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Set table and column comments. |
28
|
|
|
* |
29
|
|
|
* @param \Yajra\Oci8\Schema\OracleBlueprint $blueprint |
30
|
|
|
*/ |
31
|
|
|
public function setComments(OracleBlueprint $blueprint) |
32
|
|
|
{ |
33
|
|
|
$this->commentTable($blueprint); |
34
|
|
|
|
35
|
|
|
$this->fluentComments($blueprint); |
36
|
|
|
|
37
|
|
|
$this->commentColumns($blueprint); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Run the comment on table statement. |
42
|
|
|
* Comment set by $table->comment = 'comment'; |
43
|
|
|
* |
44
|
|
|
* @param \Yajra\Oci8\Schema\OracleBlueprint $blueprint |
45
|
|
|
*/ |
46
|
|
|
private function commentTable(OracleBlueprint $blueprint) |
47
|
|
|
{ |
48
|
|
|
$table = $this->wrapValue($blueprint->getTable()); |
49
|
|
|
|
50
|
|
|
if ($blueprint->comment != null) { |
51
|
|
|
$this->connection->statement("comment on table {$table} is '{$blueprint->comment}'"); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Wrap reserved words. |
57
|
|
|
* |
58
|
|
|
* @param string $value |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
protected function wrapValue($value) |
62
|
|
|
{ |
63
|
|
|
return $this->isReserved($value) ? parent::wrapValue($value) : $value; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Add comments set via fluent setter. |
68
|
|
|
* Comments set by $table->string('column')->comment('comment'); |
69
|
|
|
* |
70
|
|
|
* @param \Yajra\Oci8\Schema\OracleBlueprint $blueprint |
71
|
|
|
*/ |
72
|
|
|
private function fluentComments(OracleBlueprint $blueprint) |
73
|
|
|
{ |
74
|
|
|
foreach ($blueprint->getColumns() as $column) { |
75
|
|
|
if (isset($column['comment'])) { |
76
|
|
|
$this->commentColumn($blueprint->getTable(), $column['name'], $column['comment']); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Run the comment on column statement |
83
|
|
|
* |
84
|
|
|
* @param string $table |
85
|
|
|
* @param string $column |
86
|
|
|
* @param string $comment |
87
|
|
|
*/ |
88
|
|
|
private function commentColumn($table, $column, $comment) |
89
|
|
|
{ |
90
|
|
|
$table = $this->wrapValue($table); |
91
|
|
|
|
92
|
|
|
$column = $this->wrapValue($column); |
93
|
|
|
|
94
|
|
|
$this->connection->statement("comment on column {$table}.{$column} is '{$comment}'"); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Add comments on columns. |
99
|
|
|
* Comments set by $table->commentColumns = ['column' => 'comment']; |
100
|
|
|
* |
101
|
|
|
* @param \Yajra\Oci8\Schema\OracleBlueprint $blueprint |
102
|
|
|
*/ |
103
|
|
|
private function commentColumns(OracleBlueprint $blueprint) |
104
|
|
|
{ |
105
|
|
|
foreach ($blueprint->commentColumns as $column => $comment) { |
106
|
|
|
$this->commentColumn($blueprint->getTable(), $column, $comment); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|