Handle TimescaleDBEnabled as bool.
This commit is contained in:
parent
5282a22879
commit
2d843ceb3f
1 changed files with 15 additions and 7 deletions
16
main.go
16
main.go
|
@ -15,6 +15,7 @@ import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
_ "time/tzdata"
|
_ "time/tzdata"
|
||||||
|
|
||||||
|
@ -147,7 +148,7 @@ type InverterSettingsData struct {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DB string `json:"db"`
|
DB string `json:"db"`
|
||||||
OpenDTU string `json:"opendtu"`
|
OpenDTU string `json:"opendtu"`
|
||||||
TimescaleDBEnabled bool `json:"timescaledb"`
|
TimescaleDB bool `json:"timescaledb"`
|
||||||
TZ string `json:"tz"`
|
TZ string `json:"tz"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +181,14 @@ func LoadConfig() Config {
|
||||||
log.Fatal("REMOTE_URL environment variable is not set.")
|
log.Fatal("REMOTE_URL environment variable is not set.")
|
||||||
}
|
}
|
||||||
|
|
||||||
config.TimescaleDBEnabled = os.Getenv("TIMESCALEDB_ENABLED")
|
timescaleDBStr := os.Getenv("TIMESCALEDB_ENABLED")
|
||||||
|
if timescaleDBStr != "" {
|
||||||
|
timescaleDB, err := strconv.ParseBool(timescaleDBStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error parsing TIMESCALEDB_ENABLED: %v", err)
|
||||||
|
}
|
||||||
|
config.TimescaleDB = timescaleDB
|
||||||
|
}
|
||||||
config.TZ = os.Getenv("TZ")
|
config.TZ = os.Getenv("TZ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +402,7 @@ func createTables(db *sql.DB) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error creating tables: ", err)
|
log.Fatal("Error creating tables: ", err)
|
||||||
}
|
}
|
||||||
timescaleEnabled := config.TimescaleDBEnabled
|
timescaleEnabled := config.TimescaleDB
|
||||||
|
|
||||||
enableTimescaleDB := `
|
enableTimescaleDB := `
|
||||||
-- CREATE EXTENSION IF NOT EXISTS timescaledb;
|
-- CREATE EXTENSION IF NOT EXISTS timescaledb;
|
||||||
|
@ -406,7 +414,7 @@ func createTables(db *sql.DB) {
|
||||||
SELECT create_hypertable('opendtu_events', 'timestamp', if_not_exists => TRUE, migrate_data => TRUE);
|
SELECT create_hypertable('opendtu_events', 'timestamp', if_not_exists => TRUE, migrate_data => TRUE);
|
||||||
SELECT create_hypertable('opendtu_hints', 'timestamp', if_not_exists => TRUE, migrate_data => TRUE);
|
SELECT create_hypertable('opendtu_hints', 'timestamp', if_not_exists => TRUE, migrate_data => TRUE);
|
||||||
`
|
`
|
||||||
if timescaleEnabled == "true" {
|
if timescaleEnabled {
|
||||||
_, err := db.Exec(enableTimescaleDB)
|
_, err := db.Exec(enableTimescaleDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error enabling TimescaleDB: ", err)
|
log.Fatal("Error enabling TimescaleDB: ", err)
|
||||||
|
|
Loading…
Reference in a new issue