Handle TimescaleDBEnabled as bool.
This commit is contained in:
parent
5282a22879
commit
2d843ceb3f
1 changed files with 15 additions and 7 deletions
22
main.go
22
main.go
|
@ -15,6 +15,7 @@ import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
_ "time/tzdata"
|
_ "time/tzdata"
|
||||||
|
|
||||||
|
@ -145,10 +146,10 @@ type InverterSettingsData struct {
|
||||||
|
|
||||||
// Config settings struct
|
// Config settings 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||||
|
@ -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