Skip to content

Commit

Permalink
Update phinx.php
Browse files Browse the repository at this point in the history
  • Loading branch information
fiahfy authored Sep 9, 2016
1 parent 07e1a63 commit a9b4e0e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions bin/files/phinx.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
'toEnv' => true
]);

$pdo = new PDO($_ENV['DB_DSN'], $_ENV['DB_USER'], $_ENV['DB_PASS']);
preg_match("/dbname=(\w+)/i", $_ENV['DB_DSN'], $parts);
$name = isset($parts[1]) ? $parts[1] : '';
preg_match("/(.*?):(.*)/", $_ENV['DB_DSN'], $parts);
$type = $parts[1];
preg_match("/host=(\w+)/", $_ENV['DB_DSN'], $parts);
$host = $parts[1];
preg_match("/dbname=(\w+)/", $_ENV['DB_DSN'], $parts);
$dbName = $parts[1];

$default = [
"adapter" => $type,
"host" => $host,
"name" => $dbName,
"user" => $_ENV['DB_USER'],
"pass" => $_ENV['DB_PASS']
];

return [
"paths" => [
Expand All @@ -18,13 +29,9 @@
"environments" => [
"default_migration_table" => "phinxlog",
"default_database" => "default",
"default" => [
"name" => $name,
"connection" => $pdo
],
"default" => $default,
"test" => [
"name" => $name . '_test',
"connection" => $pdo
]
"name" => $dbName . '_test'
] + $default
]
];

0 comments on commit a9b4e0e

Please sign in to comment.