From a9b4e0e14914f9837e941c544107cb204641008c Mon Sep 17 00:00:00 2001 From: fiahfy Date: Fri, 9 Sep 2016 09:47:18 +0900 Subject: [PATCH] Update phinx.php --- bin/files/phinx.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bin/files/phinx.php b/bin/files/phinx.php index 8ebd291..1d5f00d 100644 --- a/bin/files/phinx.php +++ b/bin/files/phinx.php @@ -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" => [ @@ -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 ] ];