1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Oci8\Schema; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
use Illuminate\Database\Connection; |
7
|
|
|
use Illuminate\Database\Schema\Builder; |
8
|
|
|
|
9
|
|
|
class OracleBuilder extends Builder |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var \Yajra\Oci8\Schema\OracleAutoIncrementHelper |
13
|
|
|
*/ |
14
|
|
|
public $helper; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var \Yajra\Oci8\Schema\Comment |
18
|
|
|
*/ |
19
|
|
|
public $comment; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param Connection $connection |
23
|
|
|
*/ |
24
|
|
|
public function __construct(Connection $connection) |
25
|
|
|
{ |
26
|
|
|
$this->connection = $connection; |
27
|
|
|
$this->grammar = $connection->getSchemaGrammar(); |
28
|
|
|
$this->helper = new OracleAutoIncrementHelper($connection); |
29
|
|
|
$this->comment = new Comment($connection); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create a new table on the schema. |
34
|
|
|
* |
35
|
|
|
* @param string $table |
36
|
|
|
* @param Closure $callback |
37
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
38
|
|
|
*/ |
39
|
|
|
public function create($table, Closure $callback) |
40
|
|
|
{ |
41
|
|
|
$blueprint = $this->createBlueprint($table); |
42
|
|
|
|
43
|
|
|
$blueprint->create(); |
44
|
|
|
|
45
|
|
|
$callback($blueprint); |
46
|
|
|
|
47
|
|
|
$this->build($blueprint); |
48
|
|
|
|
49
|
|
|
$this->comment->setComments($blueprint); |
50
|
|
|
|
51
|
|
|
$this->helper->createAutoIncrementObjects($blueprint, $table); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Changes an existing table on the schema. |
56
|
|
|
* |
57
|
|
|
* @param string $table |
58
|
|
|
* @param Closure $callback |
59
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
60
|
|
|
*/ |
61
|
|
|
public function table($table, Closure $callback) |
62
|
|
|
{ |
63
|
|
|
$blueprint = $this->createBlueprint($table); |
64
|
|
|
|
65
|
|
|
$callback($blueprint); |
66
|
|
|
|
67
|
|
|
$this->build($blueprint); |
68
|
|
|
|
69
|
|
|
$this->comment->setComments($blueprint); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Create a new command set with a Closure. |
74
|
|
|
* |
75
|
|
|
* @param string $table |
76
|
|
|
* @param Closure $callback |
77
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
78
|
|
|
*/ |
79
|
|
|
protected function createBlueprint($table, Closure $callback = null) |
80
|
|
|
{ |
81
|
|
|
$blueprint = new OracleBlueprint($table, $callback); |
82
|
|
|
$blueprint->setTablePrefix($this->connection->getTablePrefix()); |
83
|
|
|
|
84
|
|
|
return $blueprint; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Drop a table from the schema. |
89
|
|
|
* |
90
|
|
|
* @param string $table |
91
|
|
|
* @return \Illuminate\Database\Schema\Blueprint |
92
|
|
|
*/ |
93
|
|
|
public function drop($table) |
94
|
|
|
{ |
95
|
|
|
$this->helper->dropAutoIncrementObjects($table); |
96
|
|
|
parent::drop($table); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Indicate that the table should be dropped if it exists. |
101
|
|
|
* |
102
|
|
|
* @return \Illuminate\Support\Fluent |
103
|
|
|
*/ |
104
|
|
|
public function dropIfExists($table) |
105
|
|
|
{ |
106
|
|
|
$this->helper->dropAutoIncrementObjects($table); |
107
|
|
|
parent::dropIfExists($table); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|