1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Migrations; |
6
|
|
|
|
7
|
|
|
use ArangoClient\Exceptions\ArangoException; |
8
|
|
|
use ArangoClient\Schema\SchemaManager; |
9
|
|
|
use Illuminate\Database\ConnectionResolverInterface as IlluminateResolver; |
10
|
|
|
use Illuminate\Database\Migrations\DatabaseMigrationRepository as IlluminateDatabaseMigrationRepository; |
11
|
|
|
use Illuminate\Database\Query\Builder as IlluminateQueryBuilder; |
12
|
|
|
use LaravelFreelancerNL\Aranguent\Connection; |
13
|
|
|
use LaravelFreelancerNL\Aranguent\Exceptions\AranguentException; |
14
|
|
|
use LaravelFreelancerNL\Aranguent\Query\Builder; |
15
|
|
|
|
16
|
|
|
class DatabaseMigrationRepository extends IlluminateDatabaseMigrationRepository |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* The name of the migration collection. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $table; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Create a new database migration repository instance. |
27
|
|
|
*/ |
28
|
310 |
|
public function __construct(IlluminateResolver $resolver, string $table) |
29
|
|
|
{ |
30
|
310 |
|
parent::__construct($resolver, $table); |
31
|
|
|
} |
32
|
|
|
|
33
|
6 |
|
protected function getSchemaManager(): SchemaManager |
34
|
|
|
{ |
35
|
6 |
|
$connection = $this->getConnection(); |
36
|
|
|
assert($connection instanceof Connection); |
37
|
|
|
|
38
|
6 |
|
$arangoClient = $connection->getArangoClient(); |
39
|
|
|
|
40
|
6 |
|
if ($arangoClient === null) { |
41
|
|
|
throw new AranguentException('No arangodb client set.'); |
42
|
|
|
} |
43
|
|
|
|
44
|
6 |
|
return $arangoClient->schema(); |
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Create the migration repository data store. |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
4 |
|
public function createRepository() |
54
|
|
|
{ |
55
|
4 |
|
$schemaManager = $this->getSchemaManager(); |
56
|
|
|
|
57
|
4 |
|
$schemaManager->createCollection($this->table); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the list of migrations. |
62
|
|
|
* |
63
|
|
|
* @param int $steps |
64
|
|
|
* @return array<mixed> |
65
|
|
|
*/ |
66
|
11 |
|
public function getMigrations($steps) |
67
|
|
|
{ |
68
|
|
|
//TODO: the only difference with the parent function is that type of the batch value: |
69
|
|
|
// 1 instead of '1'. This should probably be changed in the Laravel framework as it |
70
|
|
|
// seems unnecessary to use a numeric string here. |
71
|
|
|
|
72
|
11 |
|
$query = $this->table() |
73
|
11 |
|
->where('batch', '>=', 1) |
74
|
11 |
|
->orderBy('batch', 'desc') |
75
|
11 |
|
->orderBy('migration', 'desc') |
76
|
11 |
|
->take($steps); |
77
|
|
|
|
78
|
11 |
|
return $query->get()->all(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Determine if the migration repository exists. |
84
|
|
|
* |
85
|
|
|
* @return bool |
86
|
|
|
* @throws ArangoException |
87
|
|
|
* @throws AranguentException |
88
|
|
|
*/ |
89
|
6 |
|
public function repositoryExists() |
90
|
|
|
{ |
91
|
6 |
|
$schemaManager = $this->getSchemaManager(); |
92
|
|
|
|
93
|
6 |
|
return $schemaManager->hasCollection($this->table); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get a query builder for the migration collection. |
98
|
|
|
* |
99
|
|
|
* @return IlluminateQueryBuilder |
100
|
|
|
*/ |
101
|
|
|
protected function collection() |
102
|
|
|
{ |
103
|
|
|
return $this->table(); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|