mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
detect postgres version for saved datasources
This commit is contained in:
parent
2606f6e715
commit
2d12801186
50
public/app/plugins/datasource/postgres/config_ctrl.ts
Normal file
50
public/app/plugins/datasource/postgres/config_ctrl.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export class PostgresConfigCtrl {
|
||||
static templateUrl = 'partials/config.html';
|
||||
|
||||
current: any;
|
||||
datasourceSrv: any;
|
||||
|
||||
/** @ngInject **/
|
||||
constructor($scope, datasourceSrv) {
|
||||
this.datasourceSrv = datasourceSrv;
|
||||
this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full';
|
||||
this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903;
|
||||
this.autoDetectPostgresVersion();
|
||||
}
|
||||
|
||||
autoDetectPostgresVersion() {
|
||||
if (!this.current.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.datasourceSrv
|
||||
.loadDatasource(this.current.name)
|
||||
.then(ds => {
|
||||
return ds.getVersion();
|
||||
})
|
||||
.then(version => {
|
||||
version = Number(version[0].text);
|
||||
let major = Math.trunc(version / 100);
|
||||
let minor = version % 100;
|
||||
let name = String(major);
|
||||
if (version < 1000) {
|
||||
name = String(major) + '.' + String(minor);
|
||||
}
|
||||
if (!_.find(this.postgresVersions, (p: any) => p.value === version)) {
|
||||
this.postgresVersions.push({ name: name, value: version });
|
||||
}
|
||||
this.current.jsonData.postgresVersion = version;
|
||||
});
|
||||
}
|
||||
|
||||
// the value portion is derived from postgres server_version_num/100
|
||||
postgresVersions = [
|
||||
{ name: '9.3', value: 903 },
|
||||
{ name: '9.4', value: 904 },
|
||||
{ name: '9.5', value: 905 },
|
||||
{ name: '9.6', value: 906 },
|
||||
{ name: '10', value: 1000 },
|
||||
];
|
||||
}
|
@ -124,6 +124,10 @@ export class PostgresDatasource {
|
||||
.then(data => this.responseParser.parseMetricFindQueryResult(refId, data));
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
return this.metricFindQuery("SELECT current_setting('server_version_num')::int/100", {});
|
||||
}
|
||||
|
||||
testDatasource() {
|
||||
return this.metricFindQuery('SELECT 1', {})
|
||||
.then(res => {
|
||||
|
@ -1,24 +1,6 @@
|
||||
import { PostgresDatasource } from './datasource';
|
||||
import { PostgresQueryCtrl } from './query_ctrl';
|
||||
|
||||
class PostgresConfigCtrl {
|
||||
static templateUrl = 'partials/config.html';
|
||||
|
||||
current: any;
|
||||
|
||||
/** @ngInject **/
|
||||
constructor($scope) {
|
||||
this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full';
|
||||
}
|
||||
|
||||
// the value portion is derived from postgres server_version_num/100
|
||||
postgresVersions = [
|
||||
{ name: '9.3.x', value: 903 },
|
||||
{ name: '9.4.x', value: 904 },
|
||||
{ name: '9.5.x', value: 905 },
|
||||
{ name: '9.6.x', value: 906 },
|
||||
];
|
||||
}
|
||||
import { PostgresConfigCtrl } from './config_ctrl';
|
||||
|
||||
const defaultQuery = `SELECT
|
||||
extract(epoch from time_column) AS time,
|
||||
|
Loading…
Reference in New Issue
Block a user