1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Fluent; |
6
|
|
|
|
7
|
|
|
trait Tables |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Indicate that the table needs to be created. |
11
|
|
|
* |
12
|
|
|
* @param array $options |
13
|
|
|
* |
14
|
|
|
* @return Fluent |
15
|
|
|
*/ |
16
|
134 |
|
public function create($options = []) |
17
|
|
|
{ |
18
|
134 |
|
$parameters = []; |
19
|
134 |
|
$parameters['options'] = $options; |
20
|
134 |
|
$parameters['explanation'] = "Create '{$this->table}' table."; |
21
|
134 |
|
$parameters['handler'] = 'table'; |
22
|
|
|
|
23
|
134 |
|
return $this->addCommand('create', $parameters); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Determine if the blueprint has a create command. |
28
|
|
|
* |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
|
|
protected function creating() |
32
|
|
|
{ |
33
|
|
|
return collect($this->commands)->contains(function ($command) { |
34
|
|
|
return $command->name === 'create'; |
35
|
|
|
}); |
36
|
|
|
} |
37
|
|
|
|
38
|
134 |
|
public function executeCreateCommand($command) |
39
|
|
|
{ |
40
|
134 |
|
if ($this->connection->pretending()) { |
41
|
|
|
$this->connection->logQuery('/* ' . $command->explanation . " */\n", []); |
42
|
|
|
|
43
|
|
|
return; |
44
|
|
|
} |
45
|
134 |
|
$options = $command->options; |
46
|
134 |
|
if ($this->temporary === true) { |
47
|
|
|
$options['isVolatile'] = true; |
48
|
|
|
} |
49
|
134 |
|
if ($this->autoIncrement === true) { |
50
|
|
|
$options['keyOptions']['autoincrement'] = true; |
51
|
|
|
} |
52
|
|
|
|
53
|
134 |
|
if (! $this->schemaManager->hasCollection($this->table)) { |
54
|
3 |
|
$this->schemaManager->createCollection($this->table, $options); |
55
|
|
|
} |
56
|
134 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Alias for getCollection. |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getTable() |
64
|
|
|
{ |
65
|
|
|
return $this->table; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Rename the table to a given name. |
70
|
|
|
* |
71
|
|
|
* @param string $to |
72
|
|
|
* |
73
|
|
|
* @return Fluent |
74
|
|
|
*/ |
75
|
|
|
public function rename($to) |
76
|
|
|
{ |
77
|
|
|
return $this->addCommand('rename', compact('to')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Indicate that the table should be dropped. |
82
|
|
|
* |
83
|
|
|
* @return Fluent |
84
|
|
|
*/ |
85
|
|
|
public function drop() |
86
|
|
|
{ |
87
|
|
|
$parameters = []; |
88
|
|
|
$parameters['explanation'] = "Drop the '{$this->table}' table."; |
89
|
|
|
$parameters['handler'] = 'table'; |
90
|
|
|
|
91
|
|
|
return $this->addCommand('drop', $parameters); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Indicate that the table should be dropped if it exists. |
96
|
|
|
* |
97
|
|
|
* @return Fluent |
98
|
|
|
*/ |
99
|
|
|
public function dropIfExists() |
100
|
|
|
{ |
101
|
|
|
$parameters = []; |
102
|
|
|
$parameters['explanation'] = "Drop the '{$this->table}' table."; |
103
|
|
|
$parameters['handler'] = 'table'; |
104
|
|
|
|
105
|
|
|
return $this->addCommand('dropIfExists'); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|