config_ctrl.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import _ from 'lodash';
  2. export class PostgresConfigCtrl {
  3. static templateUrl = 'partials/config.html';
  4. current: any;
  5. datasourceSrv: any;
  6. /** @ngInject **/
  7. constructor($scope, datasourceSrv) {
  8. this.datasourceSrv = datasourceSrv;
  9. this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full';
  10. this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903;
  11. this.autoDetectFeatures();
  12. }
  13. autoDetectFeatures() {
  14. if (!this.current.id) {
  15. return;
  16. }
  17. this.datasourceSrv.loadDatasource(this.current.name).then(ds => {
  18. return ds.getVersion().then(version => {
  19. version = Number(version[0].text);
  20. // timescaledb is only available for 9.6+
  21. if (version >= 906) {
  22. ds.getTimescaleDBVersion().then(version => {
  23. if (version.length === 1) {
  24. this.current.jsonData.timescaledb = true;
  25. }
  26. });
  27. }
  28. let major = Math.trunc(version / 100);
  29. let minor = version % 100;
  30. let name = String(major);
  31. if (version < 1000) {
  32. name = String(major) + '.' + String(minor);
  33. }
  34. if (!_.find(this.postgresVersions, (p: any) => p.value === version)) {
  35. this.postgresVersions.push({ name: name, value: version });
  36. }
  37. this.current.jsonData.postgresVersion = version;
  38. });
  39. });
  40. }
  41. // the value portion is derived from postgres server_version_num/100
  42. postgresVersions = [
  43. { name: '9.3', value: 903 },
  44. { name: '9.4', value: 904 },
  45. { name: '9.5', value: 905 },
  46. { name: '9.6', value: 906 },
  47. { name: '10', value: 1000 },
  48. ];
  49. }