1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Oci8\Schema; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Connection; |
6
|
|
|
|
7
|
|
|
class Comment |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var \Illuminate\Database\Connection |
11
|
|
|
*/ |
12
|
|
|
protected $connection; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param Connection $connection |
16
|
|
|
*/ |
17
|
|
|
public function __construct(Connection $connection) |
18
|
|
|
{ |
19
|
|
|
$this->connection = $connection; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Set table and column comments. |
24
|
|
|
* |
25
|
|
|
* @param \Yajra\Oci8\Schema\OracleBlueprint $blueprint |
26
|
|
|
*/ |
27
|
|
|
public function setComments(OracleBlueprint $blueprint) |
28
|
|
|
{ |
29
|
|
|
// Comment set by $table->comment = 'comment'; |
30
|
|
|
if ($blueprint->comment != null) |
31
|
|
|
{ |
32
|
|
|
$this->connection->statement(sprintf('comment on table %s is \'%s\'', $blueprint->getTable(), $blueprint->comment)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// Comments set by $table->string('column')->comment('comment'); |
36
|
|
|
foreach ($blueprint->getColumns() as $column) |
37
|
|
|
{ |
38
|
|
|
if (isset($column['comment'])) |
39
|
|
|
{ |
40
|
|
|
$this->commentColumn($blueprint->getTable(), $column['name'], $column['comment']); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Comments set by $table->commentColumns = ['column' => 'comment']; |
45
|
|
|
foreach ($blueprint->commentColumns as $column => $comment) |
46
|
|
|
{ |
47
|
|
|
$this->commentColumn($blueprint->getTable(), $column, $comment); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Run the comment on column statement |
53
|
|
|
* |
54
|
|
|
* @param string $table |
55
|
|
|
* @param string $column |
56
|
|
|
* @param string $comment |
57
|
|
|
*/ |
58
|
|
|
private function commentColumn($table, $column, $comment) |
59
|
|
|
{ |
60
|
|
|
$this->connection->statement(sprintf('comment on column %s.%s is \'%s\'', $table, $column, $comment)); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|