|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Testing; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Foundation\Testing\DatabaseTruncation as IlluminateDatabaseTruncation; |
|
8
|
|
|
use LaravelFreelancerNL\Aranguent\Testing\Concerns\CanConfigureMigrationCommands; |
|
9
|
|
|
|
|
10
|
|
|
trait DatabaseTruncation |
|
11
|
|
|
{ |
|
12
|
|
|
use IlluminateDatabaseTruncation; |
|
13
|
|
|
use CanConfigureMigrationCommands; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The parameters that should be used when running "migrate:fresh". |
|
17
|
|
|
* |
|
18
|
|
|
* Duplicate code because CanConfigureMigrationCommands has a conflict otherwise. |
|
19
|
|
|
* |
|
20
|
|
|
* @return array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function migrateFreshUsing() |
|
23
|
|
|
{ |
|
24
|
|
|
$seeder = $this->seeder(); |
|
25
|
|
|
|
|
26
|
|
|
$results = array_merge( |
|
27
|
|
|
[ |
|
28
|
|
|
'--drop-analyzers' => $this->shouldDropAnalyzers(), |
|
29
|
|
|
'--drop-graphs' => $this->shouldDropGraphs(), |
|
30
|
|
|
'--drop-views' => $this->shouldDropViews(), |
|
31
|
|
|
'--drop-types' => $this->shouldDropTypes(), |
|
32
|
|
|
'--drop-all' => $this->shouldDropAll(), |
|
33
|
|
|
], |
|
34
|
|
|
$seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()], |
|
35
|
|
|
$this->setMigrationPaths(), |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
return $results; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Determine if a table exists in the given list, with or without its schema. |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function tableExistsIn(array $table, array $tables): bool |
|
45
|
|
|
{ |
|
46
|
|
|
return isset($table['schema']) |
|
47
|
|
|
? ! empty(array_intersect([$table['name'], $table['schema'] . '.' . $table['name']], $tables)) |
|
48
|
|
|
: in_array($table['name'], $tables); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|