|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Support\Fluent; |
|
8
|
|
|
|
|
9
|
|
|
trait TableCommands |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Indicate that the table needs to be created. |
|
13
|
|
|
* |
|
14
|
|
|
* @param array $options |
|
15
|
|
|
* @return Fluent |
|
16
|
|
|
*/ |
|
17
|
67 |
|
public function create($options = []) |
|
18
|
|
|
{ |
|
19
|
67 |
|
$parameters = []; |
|
20
|
67 |
|
$parameters['options'] = $options; |
|
21
|
67 |
|
$parameters['explanation'] = "Create '{$this->table}' table."; |
|
22
|
67 |
|
$parameters['handler'] = 'table'; |
|
23
|
|
|
|
|
24
|
67 |
|
return $this->addCommand('create', $parameters); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $command |
|
29
|
|
|
* @param mixed[] $args |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
49 |
|
public function handleKeyCommands($command, $args) |
|
33
|
|
|
{ |
|
34
|
49 |
|
$acceptedKeyFields = ['id', '_id', '_key']; |
|
35
|
|
|
|
|
36
|
49 |
|
$columns = ($command === 'autoIncrement') ? end($this->columns) : $args; |
|
37
|
49 |
|
$columns = (is_array($columns)) ? $columns : [$columns]; |
|
38
|
|
|
|
|
39
|
49 |
|
if (count($columns) !== 1 || ! in_array($columns[0], $acceptedKeyFields)) { |
|
40
|
|
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
49 |
|
if ($command === 'uuid') { |
|
44
|
2 |
|
$this->keyGenerator = 'uuid'; |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
2 |
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
47 |
|
if (config('arangodb.schema.key_handling.use_traditional_over_autoincrement') === false) { |
|
50
|
2 |
|
$this->keyGenerator = 'autoincrement'; |
|
51
|
|
|
|
|
52
|
2 |
|
return; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
45 |
|
$this->keyGenerator = 'traditional'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
67 |
|
public function executeCreateCommand($command) |
|
59
|
|
|
{ |
|
60
|
67 |
|
if ($this->connection->pretending()) { |
|
61
|
|
|
$this->connection->logQuery('/* ' . $command->explanation . " */\n", []); |
|
62
|
|
|
|
|
63
|
|
|
return; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
67 |
|
$options = $command->options; |
|
67
|
67 |
|
$options['keyOptions'] = $this->setKeyOptions($options['keyOptions'] ?? []); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
67 |
|
if (!$this->schemaManager->hasCollection($this->table)) { |
|
70
|
66 |
|
$this->schemaManager->createCollection($this->table, $options); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|