|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Databases\Migrations; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Databases\QueryFileLoader; |
|
|
|
|
|
|
8
|
|
|
use DateTime; |
|
9
|
|
|
use Opulence\Databases\IConnection; |
|
10
|
|
|
use Opulence\Databases\Migrations\Migration; |
|
11
|
|
|
|
|
12
|
|
|
abstract class RawMigration extends Migration |
|
13
|
|
|
{ |
|
14
|
|
|
const FILENAME = ''; |
|
15
|
|
|
|
|
16
|
|
|
const UP = 'up'; |
|
17
|
|
|
const DOWN = 'down'; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
protected $migrationsPath; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $driver; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Init constructor. |
|
27
|
|
|
* |
|
28
|
|
|
* @param IConnection $connection |
|
29
|
|
|
* @param string $migrationsPath |
|
30
|
|
|
* @param string $driver |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(IConnection $connection, string $migrationsPath, string $driver) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($connection); |
|
35
|
|
|
|
|
36
|
|
|
$this->migrationsPath = $migrationsPath; |
|
37
|
|
|
$this->driver = $driver; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Gets the creation date, which is used for ordering |
|
42
|
|
|
* |
|
43
|
|
|
* @return DateTime The date this migration was created |
|
44
|
|
|
*/ |
|
45
|
|
|
abstract public static function getCreationDate(): DateTime; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Executes the query that rolls back the migration |
|
49
|
|
|
*/ |
|
50
|
|
|
public function down(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$sql = $this->load(static::FILENAME, static::DOWN); |
|
53
|
|
|
$statement = $this->connection->prepare($sql); |
|
54
|
|
|
$statement->execute(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Executes the query that commits the migration |
|
59
|
|
|
*/ |
|
60
|
|
|
public function up(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$sql = $this->load(static::FILENAME, static::UP); |
|
63
|
|
|
$statement = $this->connection->prepare($sql); |
|
64
|
|
|
$statement->execute(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $filename |
|
69
|
|
|
* @param string $direction |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function load(string $filename, string $direction): string |
|
74
|
|
|
{ |
|
75
|
|
|
$fullPath = sprintf('%s/%s/%s/%s', $this->migrationsPath, $this->driver, $direction, $filename); |
|
76
|
|
|
|
|
77
|
|
|
return (string)file_get_contents($fullPath); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths