All registry keys must exist as rows in the config table: main seeds missing keys with their defaults at startup, LoadApp fails fast on a missing key, and the code-side fallback const/helper for the onboarding setup timeout is gone -- the value rides in SessionConfig.SetupTimeout. The key is renamed session.idle_timeout -> session.setup_timeout, and the /config page's 'overridden' now means 'differs from the default'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// ConfigValues returns every application-configuration row as key ->
|
|
// value. The table holds a row for every registry key: main seeds missing
|
|
// keys with their defaults at startup, so downstream code never needs a
|
|
// code-side fallback.
|
|
func (db *DB) ConfigValues(ctx context.Context) (map[string]string, error) {
|
|
rows, err := db.QueryContext(ctx, `SELECT key, value FROM config`)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("config values: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
values := map[string]string{}
|
|
for rows.Next() {
|
|
var k, v string
|
|
if err := rows.Scan(&k, &v); err != nil {
|
|
return nil, fmt.Errorf("scan config row: %w", err)
|
|
}
|
|
values[k] = v
|
|
}
|
|
return values, rows.Err()
|
|
}
|
|
|
|
// SetConfigValue upserts one override row. Key validation is the caller's
|
|
// job (config.ValidateAppValue) -- the store stays a dumb K/V layer.
|
|
func (db *DB) SetConfigValue(ctx context.Context, key, value string) error {
|
|
if _, err := db.ExecContext(ctx, `
|
|
INSERT INTO config (key, value, updated_at) VALUES (?, ?, datetime('now'))
|
|
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at`,
|
|
key, value); err != nil {
|
|
return fmt.Errorf("set config %q: %w", key, err)
|
|
}
|
|
return nil
|
|
}
|