Quellcode durchsuchen

autodetect timescaledb when version >= 9.6

Sven Klemm vor 7 Jahren
Ursprung
Commit
a2f4441f9d

+ 15 - 8
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

+ 4 - 0
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 => {