autodetect timescaledb when version >= 9.6

This commit is contained in:
Sven Klemm
2018-08-15 10:41:06 +02:00
parent 2d12801186
commit a2f4441f9d
2 changed files with 19 additions and 8 deletions

View File

@ -11,21 +11,27 @@ export class PostgresConfigCtrl {
this.datasourceSrv = datasourceSrv; this.datasourceSrv = datasourceSrv;
this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full'; this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full';
this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903; this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903;
this.autoDetectPostgresVersion(); this.autoDetectFeatures();
} }
autoDetectPostgresVersion() { autoDetectFeatures() {
if (!this.current.id) { if (!this.current.id) {
return; return;
} }
this.datasourceSrv this.datasourceSrv.loadDatasource(this.current.name).then(ds => {
.loadDatasource(this.current.name) return ds.getVersion().then(version => {
.then(ds => {
return ds.getVersion();
})
.then(version => {
version = Number(version[0].text); version = Number(version[0].text);
// timescaledb is only available for 9.6+
if (version >= 906) {
ds.getTimescaleDBVersion().then(version => {
if (version.length === 1) {
this.current.jsonData.timescaledb = true;
}
});
}
let major = Math.trunc(version / 100); let major = Math.trunc(version / 100);
let minor = version % 100; let minor = version % 100;
let name = String(major); let name = String(major);
@ -37,6 +43,7 @@ export class PostgresConfigCtrl {
} }
this.current.jsonData.postgresVersion = version; this.current.jsonData.postgresVersion = version;
}); });
});
} }
// the value portion is derived from postgres server_version_num/100 // the value portion is derived from postgres server_version_num/100

View File

@ -128,6 +128,10 @@ export class PostgresDatasource {
return this.metricFindQuery("SELECT current_setting('server_version_num')::int/100", {}); return this.metricFindQuery("SELECT current_setting('server_version_num')::int/100", {});
} }
getTimescaleDBVersion() {
return this.metricFindQuery("SELECT extversion FROM pg_extension WHERE extname = 'timescaledb'", {});
}
testDatasource() { testDatasource() {
return this.metricFindQuery('SELECT 1', {}) return this.metricFindQuery('SELECT 1', {})
.then(res => { .then(res => {