From 19aed53feeab10f09c822abb8f1597acb2f213bc Mon Sep 17 00:00:00 2001 From: dwrz Date: Sun, 20 Sep 2026 12:27:03 +0000 Subject: [PATCH] Add database config --- internal/config/config.go | 22 +++++++++++++++++ internal/config/config_test.go | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index 45ba5dc..22fd9d2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -41,6 +41,19 @@ func (cfg TTS) Validate() error { return nil } +// Database holds the SQLite database configuration. +type Database struct { + // Path is the filesystem path to the SQLite database file. + Path string `yaml:"path"` +} + +func (cfg Database) Validate() error { + if cfg.Path == "" { + return fmt.Errorf("missing path") + } + return nil +} + // STT holds the configuration for the frontend-facing speech-to-text server. type STT struct { // URL is the base URL of the whisper-server. @@ -115,6 +128,9 @@ type JobConfig struct { Task string `yaml:"task"` // Timeout limits the job execution time (e.g., "10m"). Timeout string `yaml:"timeout,omitempty"` + // UserId identifies the user that owns conversations created by this job. + // It is assigned by the service until jobs are stored in the database. + UserId string `yaml:"user_id,omitempty"` } func (cfg JobConfig) Validate() error { @@ -130,6 +146,7 @@ func (cfg JobConfig) Validate() error { if cfg.MaxIterations < 0 { return fmt.Errorf("max_iterations must be non-negative") } + return nil } @@ -171,6 +188,8 @@ func (cfg ToolConfig) Validate() error { type Config struct { // Address is the host:port to listen on. Address string `yaml:"address"` + // Database configures the SQLite database path. + Database Database `yaml:"database"` // ShutdownTimeout is the maximum time to wait for graceful shutdown. ShutdownTimeout string `yaml:"shutdown_timeout"` // shutdownTimeout is the parsed duration, set during Load. @@ -211,6 +230,9 @@ func (cfg *Config) Validate() error { if cfg.Address == "" { return fmt.Errorf("address required") } + if err := cfg.Database.Validate(); err != nil { + return fmt.Errorf("invalid database config: %w", err) + } if cfg.DefaultModel.Provider == "" { return fmt.Errorf("default_model.provider required") } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 4f2f8bc..502b08c 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -14,6 +14,9 @@ func validConfig() string { address: ":9090" shutdown_timeout: "60s" +database: + path: "/tmp/odidere-test.db" + default_model: provider: testprovider model: test-model @@ -76,6 +79,9 @@ func TestLoad(t *testing.T) { { name: "defaults applied", config: ` +database: + path: "/tmp/odidere-test.db" + default_model: provider: testprovider model: test-model @@ -115,6 +121,9 @@ tts: { name: "env expansion", config: ` +database: + path: "/tmp/odidere-test.db" + default_model: provider: testprovider model: test-model @@ -149,6 +158,9 @@ tts: { name: "env expansion unset var becomes empty", config: ` +database: + path: "/tmp/odidere-test.db" + default_model: provider: testprovider model: test-model @@ -182,6 +194,29 @@ tts: config: `providers: [invalid yaml`, shouldErr: true, }, + { + name: "missing database path", + config: ` +address: ":9090" +shutdown_timeout: "60s" + +default_model: + provider: testprovider + model: test-model + +providers: + - name: testprovider + url: http://localhost:8080 + +stt: + url: http://localhost:8178 + +tts: + url: http://localhost:8880 + voice: af_heart +`, + shouldErr: true, + }, { name: "invalid shutdown_timeout", config: ` @@ -322,6 +357,9 @@ tts: { name: "config with tools", config: ` +database: + path: "/tmp/odidere-test.db" + default_model: provider: testprovider model: test-model @@ -462,6 +500,9 @@ func TestLoad_Jobs(t *testing.T) { { name: "valid job config", config: ` +database: + path: "/tmp/odidere-test.db" + default_model: provider: testprovider model: test-model @@ -514,6 +555,9 @@ jobs: { name: "job with minimal config (defaults)", config: ` +database: + path: "/tmp/odidere-test.db" + default_model: provider: testprovider model: test-model