fix: 修复 Docker Compose 环境下 PostgreSQL 连接失败 #115

Merged
huanghaosheng merged 2 commits from develop into main 2026-06-14 20:50:31 +08:00
3 changed files with 12 additions and 1 deletions
Showing only changes of commit 6db5bef519 - Show all commits

View File

@@ -56,6 +56,10 @@ func main() {
var sessRepo store.SessionRepository var sessRepo store.SessionRepository
if cfg.Storage.Driver == "postgres" { if cfg.Storage.Driver == "postgres" {
if cfg.Storage.DSN == "" {
logger.Log.Fatalw("storage.dsn is required when storage.driver is postgres",
"hint", "set CAMTALK_STORAGE_DSN environment variable")
}
pool, err := store.NewPostgresPool(ctx, cfg.Storage.DSN) pool, err := store.NewPostgresPool(ctx, cfg.Storage.DSN)
if err != nil { if err != nil {
logger.Log.Fatalw("failed to connect to postgres", "error", err) logger.Log.Fatalw("failed to connect to postgres", "error", err)

View File

@@ -152,6 +152,7 @@ func Load() (*Config, error) {
v.SetDefault("ai.tts.output_format", "mp3") v.SetDefault("ai.tts.output_format", "mp3")
v.SetDefault("ai.tts.sample_rate", 24000) v.SetDefault("ai.tts.sample_rate", 24000)
v.SetDefault("storage.driver", "memory") v.SetDefault("storage.driver", "memory")
v.SetDefault("storage.dsn", "")
v.SetDefault("log.level", "info") v.SetDefault("log.level", "info")
v.SetDefault("log.format", "console") v.SetDefault("log.format", "console")
v.SetDefault("auth.access_ttl", 15) v.SetDefault("auth.access_ttl", 15)

View File

@@ -23,7 +23,8 @@ services:
- CAMTALK_STORAGE_DSN=postgres://camtalk:camtalk123@postgres:5432/camtalk?sslmode=disable - CAMTALK_STORAGE_DSN=postgres://camtalk:camtalk123@postgres:5432/camtalk?sslmode=disable
- CAMTALK_AUTH_JWT_SECRET=78uWBBAF8XEQEotKDlrnlnd4y8i4WN3E4zXmNmC8BYQ= - CAMTALK_AUTH_JWT_SECRET=78uWBBAF8XEQEotKDlrnlnd4y8i4WN3E4zXmNmC8BYQ=
depends_on: depends_on:
- postgres postgres:
condition: service_healthy
networks: networks:
- camtalk-net - camtalk-net
restart: unless-stopped restart: unless-stopped
@@ -41,6 +42,11 @@ services:
- ./backend/migrations:/docker-entrypoint-initdb.d - ./backend/migrations:/docker-entrypoint-initdb.d
networks: networks:
- camtalk-net - camtalk-net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U camtalk -d camtalk"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped restart: unless-stopped
volumes: volumes: