-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathphinx.php
More file actions
82 lines (73 loc) · 3.06 KB
/
Copy pathphinx.php
File metadata and controls
82 lines (73 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Phinx Configuration
*
* Liest DB-Credentials aus .env (vlucas/phpdotenv).
* Migrations liegen unter database/migrations/.
*
* Aufruf:
* vendor/bin/phinx migrate -e production
* vendor/bin/phinx status -e production
*
* Im Code wird Phinx programmatisch via App\Database\AutoMigrator aufgerufen,
* sodass auch Webspaces ohne Shell-Zugang funktionieren.
*/
require_once __DIR__ . '/vendor/autoload.php';
// .env best-effort laden (Produktion + lokale Entwicklung). In der CI gibt es
// keine .env — dort kommen die DB_*-Variablen direkt aus der Prozess-Umgebung.
if (is_file(__DIR__ . '/.env')) {
try {
Dotenv\Dotenv::createImmutable(__DIR__, null, false)->load();
} catch (\Throwable $e) {
// Erlaubt Phinx-CLI-Aufrufe ohne lesbare .env (z.B. für `phinx init`).
}
}
// $_ENV ist je nach variables_order leer, selbst wenn OS-Env-Variablen gesetzt
// sind (Standard bei PHP-CLI in CI). Daher robust über $_ENV/$_SERVER/getenv()
// auflösen, sonst landet Phinx auf 'localhost' + leerer DB → [2002] Socket-Fehler.
$env = static function (string $key, ?string $default = null): ?string {
$val = $_ENV[$key] ?? $_SERVER[$key] ?? getenv($key);
return ($val === false || $val === null || $val === '') ? $default : (string) $val;
};
return [
'paths' => [
// Kern-Migrations plus die Migrations-Verzeichnisse installierter
// Plugins. Installiert = mitgeliefert oder vom Admin bestätigt —
// ein bloß nach plugins/ kopiertes Fremd-Plugin migriert nichts.
// Deaktivierte (aber installierte) Plugins bleiben drin: ihr
// Schema gehört erhalten. Die Filterlogik lebt im PluginLoader
// und ist datenbankfrei, damit sie auch hier in der CLI läuft.
'migrations' => array_merge(
[__DIR__ . '/database/migrations'],
class_exists(\App\Plugins\PluginLoader::class)
? \App\Plugins\PluginLoader::migrationPaths()
: [],
),
'seeds' => __DIR__ . '/database/seeds',
],
'environments' => [
'default_migration_table' => 'phinxlog',
'default_environment' => 'production',
'production' => [
'adapter' => 'mysql',
'host' => $env('DB_HOST', 'localhost'),
'name' => $env('DB_NAME', ''),
'user' => $env('DB_USER', ''),
'pass' => $env('DB_PASS', ''),
'port' => (int) $env('DB_PORT', '3306'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
],
'testing' => [
'adapter' => 'mysql',
'host' => $env('DB_TEST_HOST', $env('DB_HOST', 'localhost')),
'name' => $env('DB_TEST_NAME', 'intrarp_test'),
'user' => $env('DB_TEST_USER', $env('DB_USER', '')),
'pass' => $env('DB_TEST_PASS', $env('DB_PASS', '')),
'port' => (int) $env('DB_TEST_PORT', '3306'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
],
],
'version_order' => 'creation',
];