feat(legacy): add db config defaults and allow custom port (#1559)
* feat(legacy): allow custom port for database connection - fix heredoc for php72 * update test config db section * update sample config db section * update api db config * use defaults for database config section * update documentation * more documentation for migration
This commit is contained in:
parent
71b3e6aa9d
commit
3245216869
12 changed files with 95 additions and 49 deletions
|
@ -11,7 +11,8 @@
|
|||
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
$dbhost = $CC_CONFIG['dsn']['hostspec'];
|
||||
$dbhost = $CC_CONFIG['dsn']['host'];
|
||||
$dbport = $CC_CONFIG['dsn']['port'];
|
||||
$dbname = $CC_CONFIG['dsn']['database'];
|
||||
$dbuser = $CC_CONFIG['dsn']['username'];
|
||||
$dbpass = $CC_CONFIG['dsn']['password'];
|
||||
|
@ -21,7 +22,7 @@ $conf = [
|
|||
'airtime' => [
|
||||
'adapter' => 'pgsql',
|
||||
'connection' => [
|
||||
'dsn' => "pgsql:host={$dbhost};port=5432;dbname={$dbname};user={$dbuser};password={$dbpass}",
|
||||
'dsn' => "pgsql:host={$dbhost};port={$dbport};dbname={$dbname};user={$dbuser};password={$dbpass}",
|
||||
],
|
||||
],
|
||||
'default' => 'airtime',
|
||||
|
|
|
@ -49,11 +49,12 @@ class Config
|
|||
$CC_CONFIG['cache_ahead_hours'] = $values['general']['cache_ahead_hours'];
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
|
||||
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
|
||||
$CC_CONFIG['dsn']['host'] = $values['database']['host'] ?? 'localhost';
|
||||
$CC_CONFIG['dsn']['port'] = $values['database']['port'] ?? 5432;
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['name'] ?? 'libretime';
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['user'] ?? 'libretime';
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['password'] ?? 'libretime';
|
||||
|
||||
$CC_CONFIG['apiKey'] = [$values['general']['api_key']];
|
||||
|
||||
|
|
|
@ -83,7 +83,8 @@ class Application_Model_Auth
|
|||
|
||||
// Database config
|
||||
$db = Zend_Db::factory('PDO_' . $CC_CONFIG['dsn']['phptype'], [
|
||||
'host' => $CC_CONFIG['dsn']['hostspec'],
|
||||
'host' => $CC_CONFIG['dsn']['host'],
|
||||
'port' => $CC_CONFIG['dsn']['port'],
|
||||
'username' => $CC_CONFIG['dsn']['username'],
|
||||
'password' => $CC_CONFIG['dsn']['password'],
|
||||
'dbname' => $CC_CONFIG['dsn']['database'],
|
||||
|
|
|
@ -119,10 +119,11 @@ abstract class AirtimeUpgrader
|
|||
{
|
||||
protected $_dir;
|
||||
|
||||
protected $host;
|
||||
protected $port;
|
||||
protected $database;
|
||||
protected $username;
|
||||
protected $password;
|
||||
protected $host;
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* @param $dir string directory housing upgrade files
|
||||
|
@ -241,22 +242,45 @@ abstract class AirtimeUpgrader
|
|||
{
|
||||
$config = Config::getConfig();
|
||||
|
||||
$this->host = $config['dsn']['host'];
|
||||
$this->port = $config['dsn']['port'];
|
||||
$this->username = $config['dsn']['username'];
|
||||
$this->password = $config['dsn']['password'];
|
||||
$this->host = $config['dsn']['hostspec'];
|
||||
$this->database = $config['dsn']['database'];
|
||||
}
|
||||
|
||||
protected function _runPsql($args)
|
||||
{
|
||||
$command = <<<"END"
|
||||
PGPASSWORD={$this->password} \\
|
||||
/usr/bin/psql --quiet \\
|
||||
--host={$this->host} \\
|
||||
--port={$this->port} \\
|
||||
--dbname={$this->database} \\
|
||||
--username={$this->username} \\
|
||||
{$args}
|
||||
END;
|
||||
passthru($command);
|
||||
}
|
||||
|
||||
protected function _runUpgrade()
|
||||
{
|
||||
passthru('export PGPASSWORD=' . $this->password . ' && /usr/bin/psql -h ' . $this->host . ' -U ' . $this->username . ' -q -f ' . $this->_dir . '/upgrade_sql/airtime_'
|
||||
. $this->getNewVersion() . '/upgrade.sql ' . $this->database . ' 2>&1 | grep -v -E "will create implicit sequence|will create implicit index"');
|
||||
$sqlFile = "{$this->_dir}/upgrade_sql/airtime_{$this->getNewVersion()}/upgrade.sql";
|
||||
$args = <<<"END"
|
||||
--file={$sqlFile} 2>&1 \\
|
||||
| grep -v -E "will create implicit sequence|will create implicit index"
|
||||
END;
|
||||
$this->_runPsql($args);
|
||||
}
|
||||
|
||||
protected function _runDowngrade()
|
||||
{
|
||||
passthru('export PGPASSWORD=' . $this->password . ' && /usr/bin/psql -h ' . $this->host . ' -U ' . $this->username . ' -q -f ' . $this->_dir . '/downgrade_sql/airtime_'
|
||||
. $this->getNewVersion() . '/downgrade.sql ' . $this->database . ' 2>&1 | grep -v -E "will create implicit sequence|will create implicit index"');
|
||||
$sqlFile = "{$this->_dir}/downgrade_sql/airtime_{$this->getNewVersion()}/downgrade.sql";
|
||||
$args = <<<"END"
|
||||
--file={$sqlFile} 2>&1 \\
|
||||
| grep -v -E "will create implicit sequence|will create implicit index"
|
||||
END;
|
||||
$this->_runPsql($args);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue