@ -8,13 +8,11 @@ $config = array();
if (getenv($ename . '_TYPE') !== false) {
if (getenv($ename . '_TYPE') !== false) {
$config['DB_TYPE'] = getenv($ename . '_TYPE');
$config['DB_TYPE'] = getenv($ename . '_TYPE');
}
} elseif (getenv($ename . '_PORT_5432_TCP_ADDR') !== false) {
elseif(getenv($ename . '_PORT_5432_TCP_ADDR') !== false) {
// postgres container linked
// postgres container linked
$config['DB_TYPE'] = 'pgsql';
$config['DB_TYPE'] = 'pgsql';
$eport = 5432;
$eport = 5432;
}
} elseif (getenv($ename . '_PORT_3306_TCP_ADDR') !== false) {
elseif(getenv($ename . '_PORT_3306_TCP_ADDR') !== false) {
// mysql container linked
// mysql container linked
$config['DB_TYPE'] = 'mysql';
$config['DB_TYPE'] = 'mysql';
$eport = 3306;
$eport = 3306;
@ -23,11 +21,9 @@ elseif(getenv($ename . '_PORT_3306_TCP_ADDR') !== false) {
if (!empty($eport)) {
if (!empty($eport)) {
$config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR');
$config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR');
$config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT');
$config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT');
}
} elseif (getenv($ename . '_PORT') === false) {
elseif(getenv($ename . '_PORT') === false) {
error('The env ' . $ename . '_PORT does not exist. Make sure to run with "--link mypostgresinstance:' . $ename . '"');
error('The env ' . $ename . '_PORT does not exist. Make sure to run with "--link mypostgresinstance:' . $ename . '"');
}
} elseif (is_numeric(getenv($ename . '_PORT')) & & getenv($ename . '_HOST') !== false) {
elseif(is_numeric(getenv($ename . '_PORT')) & & getenv($ename . '_HOST') !== false) {
// numeric DB_PORT provided; assume port number passed directly
// numeric DB_PORT provided; assume port number passed directly
$config['DB_HOST'] = env($ename . '_HOST');
$config['DB_HOST'] = env($ename . '_HOST');
$config['DB_PORT'] = env($ename . '_PORT');
$config['DB_PORT'] = env($ename . '_PORT');
@ -68,11 +64,10 @@ if (!dbcheck($config)) {
$pdo = dbconnect($super);
$pdo = dbconnect($super);
if($super['DB_TYPE'] == 'mysql') {
if ($super['DB_TYPE'] = == 'mysql') {
$pdo->exec('CREATE DATABASE ' . ($config['DB_NAME']));
$pdo->exec('CREATE DATABASE ' . ($config['DB_NAME']));
$pdo->exec('GRANT ALL PRIVILEGES ON ' . ($config['DB_NAME']) . '.* TO ' . $pdo->quote($config['DB_USER']) . '@"%" IDENTIFIED BY ' . $pdo->quote($config['DB_PASS']));
$pdo->exec('GRANT ALL PRIVILEGES ON ' . ($config['DB_NAME']) . '.* TO ' . $pdo->quote($config['DB_USER']) . '@"%" IDENTIFIED BY ' . $pdo->quote($config['DB_PASS']));
}
} else {
else {
$pdo->exec('CREATE ROLE ' . ($config['DB_USER']) . ' WITH LOGIN PASSWORD ' . $pdo->quote($config['DB_PASS']));
$pdo->exec('CREATE ROLE ' . ($config['DB_USER']) . ' WITH LOGIN PASSWORD ' . $pdo->quote($config['DB_PASS']));
$pdo->exec('CREATE DATABASE ' . ($config['DB_NAME']) . ' WITH OWNER ' . ($config['DB_USER']));
$pdo->exec('CREATE DATABASE ' . ($config['DB_NAME']) . ' WITH OWNER ' . ($config['DB_USER']));
}
}