From a2f4441f9d033b6c4363b33a5e27890be7420b74 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Wed, 15 Aug 2018 10:41:06 +0200 Subject: [PATCH] autodetect timescaledb when version >= 9.6 --- .../datasource/postgres/config_ctrl.ts | 23 ++++++++++++------- .../plugins/datasource/postgres/datasource.ts | 4 ++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/public/app/plugins/datasource/postgres/config_ctrl.ts b/public/app/plugins/datasource/postgres/config_ctrl.ts index 282410cfbbe..e2ec8211a9e 100644 --- a/public/app/plugins/datasource/postgres/config_ctrl.ts +++ b/public/app/plugins/datasource/postgres/config_ctrl.ts @@ -11,21 +11,27 @@ export class PostgresConfigCtrl { this.datasourceSrv = datasourceSrv; this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full'; this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903; - this.autoDetectPostgresVersion(); + this.autoDetectFeatures(); } - autoDetectPostgresVersion() { + autoDetectFeatures() { if (!this.current.id) { return; } - this.datasourceSrv - .loadDatasource(this.current.name) - .then(ds => { - return ds.getVersion(); - }) - .then(version => { + this.datasourceSrv.loadDatasource(this.current.name).then(ds => { + return ds.getVersion().then(version => { 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 minor = version % 100; let name = String(major); @@ -37,6 +43,7 @@ export class PostgresConfigCtrl { } this.current.jsonData.postgresVersion = version; }); + }); } // the value portion is derived from postgres server_version_num/100 diff --git a/public/app/plugins/datasource/postgres/datasource.ts b/public/app/plugins/datasource/postgres/datasource.ts index 9e2d67f903a..3fafe5a324c 100644 --- a/public/app/plugins/datasource/postgres/datasource.ts +++ b/public/app/plugins/datasource/postgres/datasource.ts @@ -128,6 +128,10 @@ export class PostgresDatasource { return this.metricFindQuery("SELECT current_setting('server_version_num')::int/100", {}); } + getTimescaleDBVersion() { + return this.metricFindQuery("SELECT extversion FROM pg_extension WHERE extname = 'timescaledb'", {}); + } + testDatasource() { return this.metricFindQuery('SELECT 1', {}) .then(res => {