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
|
@ -223,9 +223,10 @@ jobs:
|
|||
api_key = test_key
|
||||
[database]
|
||||
host = postgres
|
||||
dbname = libretime
|
||||
dbuser = postgres
|
||||
dbpass = libretime
|
||||
port = 5432
|
||||
name = libretime
|
||||
user = postgres
|
||||
password = libretime
|
||||
EOF
|
||||
cat $LIBRETIME_CONFIG_FILEPATH
|
||||
|
||||
|
|
|
@ -80,11 +80,11 @@ WSGI_APPLICATION = "libretime_api.wsgi.application"
|
|||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql",
|
||||
"NAME": CONFIG.get("database", "dbname", fallback=""),
|
||||
"USER": CONFIG.get("database", "dbuser", fallback=""),
|
||||
"PASSWORD": CONFIG.get("database", "dbpass", fallback=""),
|
||||
"HOST": CONFIG.get("database", "host", fallback=""),
|
||||
"PORT": "5432",
|
||||
"NAME": CONFIG.get("database", "name", fallback="libretime"),
|
||||
"USER": CONFIG.get("database", "user", fallback="libretime"),
|
||||
"PASSWORD": CONFIG.get("database", "password", fallback="libretime"),
|
||||
"HOST": CONFIG.get("database", "host", fallback="localhost"),
|
||||
"PORT": CONFIG.get("database", "port", fallback="5432"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@ You can also set options for RabbitMQ messaging and the LibreTime server in this
|
|||
|
||||
[database]
|
||||
host = localhost
|
||||
dbname = airtime
|
||||
dbuser = airtime
|
||||
dbpass = airtime
|
||||
port = 5432
|
||||
name = libretime
|
||||
user = libretime
|
||||
password = libretime
|
||||
|
||||
[rabbitmq]
|
||||
host = 127.0.0.1
|
||||
|
|
|
@ -61,7 +61,9 @@ upgrading, please [file a bug](https://github.com/libretime/libretime/issues/new
|
|||
[install](/install).
|
||||
3. Before running the web-configuration, restore the Airtime database to the new
|
||||
PostgreSQL server, media database and configuration file
|
||||
4. Edit the configuration file to update any changed values
|
||||
4. Update the configuration file to match the new configuration schema and update any
|
||||
changed values. See the [host configuration](/docs/host-configuration) documentation
|
||||
for more details.
|
||||
5. Edit the Icecast password in `/etc/icecast2/icecast.xml` to reflect the
|
||||
password used in Airtime
|
||||
6. Restart the LibreTime services
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,23 +78,27 @@ auth = local
|
|||
#
|
||||
# These settings are used to configure your database connection.
|
||||
#
|
||||
# host: The hostname of the database server.
|
||||
# On a default Airtime installation, set this to localhost.
|
||||
# host: The hostname of the database server.
|
||||
# On a default Airtime installation, set this to localhost.
|
||||
#
|
||||
# dbname: The name of the Airtime database.
|
||||
# The default is airtime.
|
||||
# port: The port of the database server.
|
||||
# On a default Airtime installation, set this to 5432.
|
||||
#
|
||||
# dbuser: The username for the Airtime database user.
|
||||
# The default is airtime.
|
||||
# name: The name of the Airtime database.
|
||||
# The default is airtime.
|
||||
#
|
||||
# dbpass: The password for the Airtime database user.
|
||||
# The default is airtime.
|
||||
# user: The username for the Airtime database user.
|
||||
# The default is airtime.
|
||||
#
|
||||
# password: The password for the Airtime database user.
|
||||
# The default is airtime.
|
||||
#
|
||||
[database]
|
||||
host = localhost
|
||||
dbname = airtime
|
||||
dbuser = airtime
|
||||
dbpass = airtime
|
||||
port = 5432
|
||||
name = airtime
|
||||
user = airtime
|
||||
password = airtime
|
||||
#
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -201,17 +201,18 @@ class AirtimeInstall
|
|||
public static function CreateDatabase()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$host = $CC_CONFIG['dsn']['host'];
|
||||
$port = $CC_CONFIG['dsn']['port'];
|
||||
$database = $CC_CONFIG['dsn']['database'];
|
||||
$username = $CC_CONFIG['dsn']['username'];
|
||||
$password = $CC_CONFIG['dsn']['password'];
|
||||
$hostspec = $CC_CONFIG['dsn']['hostspec'];
|
||||
|
||||
echo ' * Creating Airtime database: ' . $database . PHP_EOL;
|
||||
|
||||
$dbExists = false;
|
||||
|
||||
try {
|
||||
$con = pg_connect('user=' . $username . ' password=' . $password . ' host=' . $hostspec);
|
||||
$con = pg_connect("host={$host} port={$port} user={$username} password={$password}");
|
||||
|
||||
pg_query($con, 'CREATE DATABASE ' . $database . ' WITH ENCODING \'UTF8\' TEMPLATE template0 OWNER ' . $username . ';');
|
||||
} catch (Exception $e) {
|
||||
|
@ -245,7 +246,7 @@ class AirtimeInstall
|
|||
}
|
||||
}
|
||||
|
||||
public static function CreateDatabaseTables($p_dbuser, $p_dbpasswd, $p_dbname, $p_dbhost)
|
||||
public static function CreateDatabaseTables($dbuser, $dbpasswd, $dbname, $dbhost, $dbport)
|
||||
{
|
||||
echo ' * Creating database tables' . PHP_EOL;
|
||||
// Put Propel sql files in Database
|
||||
|
@ -253,7 +254,15 @@ class AirtimeInstall
|
|||
$dir = self::GetAirtimeSrcDir() . '/build/sql/';
|
||||
$files = ['schema.sql', 'sequences.sql', 'views.sql', 'triggers.sql', 'defaultdata.sql'];
|
||||
foreach ($files as $f) {
|
||||
$command = "export PGPASSWORD={$p_dbpasswd} && /usr/bin/psql --username {$p_dbuser} --dbname {$p_dbname} --host {$p_dbhost} --file {$dir}{$f} 2>&1";
|
||||
$command = <<<"END"
|
||||
PGPASSWORD={$dbpasswd} \\
|
||||
/usr/bin/psql \\
|
||||
--host={$dbhost} \\
|
||||
--port={$dbport} \\
|
||||
--dbname={$dbname} \\
|
||||
--username={$dbuser} \\
|
||||
--file {$dir}{$f} 2>&1
|
||||
END;
|
||||
@exec($command, $output, $results);
|
||||
}
|
||||
AirtimeInstall::$databaseTablesCreated = true;
|
||||
|
|
|
@ -28,7 +28,8 @@ class TestHelper
|
|||
|
||||
return new Zend_Config(
|
||||
[
|
||||
'host' => $config['dsn']['hostspec'],
|
||||
'host' => $config['dsn']['host'],
|
||||
'port' => $config['dsn']['port'],
|
||||
'dbname' => $config['dsn']['database'],
|
||||
'username' => $config['dsn']['username'],
|
||||
'password' => $config['dsn']['password'],
|
||||
|
@ -42,10 +43,11 @@ class TestHelper
|
|||
//is normally
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
$dbhost = $CC_CONFIG['dsn']['host'];
|
||||
$dbport = $CC_CONFIG['dsn']['port'];
|
||||
$dbname = $CC_CONFIG['dsn']['database'];
|
||||
$dbuser = $CC_CONFIG['dsn']['username'];
|
||||
$dbpasswd = $CC_CONFIG['dsn']['password'];
|
||||
$dbname = $CC_CONFIG['dsn']['database'];
|
||||
$dbhost = $CC_CONFIG['dsn']['hostspec'];
|
||||
|
||||
$databaseAlreadyExists = AirtimeInstall::createDatabase();
|
||||
if ($databaseAlreadyExists) {
|
||||
|
@ -123,7 +125,7 @@ class TestHelper
|
|||
$con->commit();
|
||||
} else {
|
||||
//Create all the database tables
|
||||
AirtimeInstall::CreateDatabaseTables($dbuser, $dbpasswd, $dbname, $dbhost);
|
||||
AirtimeInstall::CreateDatabaseTables($dbuser, $dbpasswd, $dbname, $dbhost, $dbport);
|
||||
AirtimeInstall::UpdateDatabaseTables();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[database]
|
||||
|
||||
host = localhost
|
||||
dbname = libretime_test
|
||||
dbuser = libretime
|
||||
dbpass = libretime
|
||||
port = 5432
|
||||
name = libretime_test
|
||||
user = libretime
|
||||
password = libretime
|
||||
|
||||
[rabbitmq]
|
||||
host = 127.0.0.1
|
||||
|
|
Loading…
Reference in New Issue