Update database schema display (#9708)

* Update database schema display

* handle missing migrations table
This commit is contained in:
Tony Murray
2019-01-22 06:47:07 -06:00
committed by GitHub
parent 45e0e5e19a
commit 8ce81f2423
4 changed files with 24 additions and 4 deletions

View File

@@ -678,7 +678,7 @@ class IRCBot
$schema_version = $versions['db_schema'];
$version = substr($versions['local_sha'], 0, 7);
$msg = $this->config['project_name_version'].', Version: '.$version.', DB schema: #'.$schema_version.', PHP: '.PHP_VERSION;
$msg = $this->config['project_name_version'].', Version: '.$version.', DB schema: '.$schema_version.', PHP: '.PHP_VERSION;
return $this->respond($msg);
}//end _version()

View File

@@ -25,6 +25,8 @@
namespace LibreNMS\Util;
use LibreNMS\DB\Eloquent;
class Version
{
// Update this on release
@@ -50,4 +52,21 @@ class Version
return self::VERSION;
}
public function database()
{
if (Eloquent::isConnected()) {
try {
$query = Eloquent::DB()->table('migrations');
return [
'last' => $query->orderBy('id', 'desc')->value('migration'),
'total' => $query->count(),
];
} catch (\Exception $e) {
return ['last' => 'No Schema', 'total' => 0];
}
}
return ['last' => 'Not Connected', 'total' => 0];
}
}

View File

@@ -170,7 +170,7 @@ echo "
<div class='table-responsive'>
<table class='table table-condensed' border='0'>
<tr><td><b>Version</b></td><td><a href='http://www.librenms.org/changelog.html'>$version - <span id='version_date'>$version_date</span></a></td></tr>
<tr><td><b>DB Schema</b></td><td>#$schema_version</td></tr>
<tr><td><b>DB Schema</b></td><td>$schema_version</td></tr>
<tr><td><b>Web Server</b></td><td>$webserv_version</td></tr>
<tr><td><b>PHP</b></td><td>$php_version</td></tr>
<tr><td><b>MySQL</b></td><td>$mysql_version</td></tr>

View File

@@ -1149,8 +1149,9 @@ function parse_location($location)
function version_info($remote = false)
{
global $config;
$version = \LibreNMS\Util\Version::get();
$output = [
'local_ver' => \LibreNMS\Util\Version::get()->local(),
'local_ver' => $version->local(),
];
if (Git::repoPresent() && Git::binaryExists()) {
if ($remote === true && $config['update_channel'] == 'master') {
@@ -1169,7 +1170,7 @@ function version_info($remote = false)
$output['local_date'] = $local_date;
$output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`);
}
$output['db_schema'] = dbIsConnected() ? get_db_schema() : '?';
$output['db_schema'] = vsprintf('%s (%s)', $version->database());
$output['php_ver'] = phpversion();
$output['mysql_ver'] = dbIsConnected() ? dbFetchCell('SELECT version()') : '?';
$output['rrdtool_ver'] = str_replace('1.7.01.7.0', '1.7.0', implode(' ', array_slice(explode(' ', shell_exec(