feat: 配置扩展与 PostgreSQL 连接池 #93

Merged
huanghaosheng merged 4 commits from feature/user-model-phase1 into develop 2026-06-14 16:50:25 +08:00
  • 扩展 Config 结构体,新增 AuthConfig(JWTSecret, AccessTTL, RefreshTTL)
  • 设置认证配置默认值:access_ttl=15分钟,refresh_ttl=10080分钟(7天)
  • 实现 PostgreSQL 连接池 NewPostgresPool
  • 编写 users 和 refresh_tokens 表的迁移脚本
  • main.go 条件初始化 DB(storage.driver == postgres)
- 扩展 Config 结构体,新增 AuthConfig(JWTSecret, AccessTTL, RefreshTTL) - 设置认证配置默认值:access_ttl=15分钟,refresh_ttl=10080分钟(7天) - 实现 PostgreSQL 连接池 NewPostgresPool - 编写 users 和 refresh_tokens 表的迁移脚本 - main.go 条件初始化 DB(storage.driver == postgres)
huanghaosheng added 4 commits 2026-06-14 16:50:18 +08:00
- 新增 AuthConfig 结构体(JWTSecret, AccessTTL, RefreshTTL)
- 在 Config 中添加 Auth 字段
- 设置默认值:access_ttl=15分钟,refresh_ttl=10080分钟(7天)
- JWTSecret 必须通过环境变量 CAMTALK_AUTH_JWT_SECRET 设置
- 新增 internal/store/db.go
- 实现 NewPostgresPool(ctx, dsn) 创建连接池
- 添加 pgx/v5 依赖
- 最大连接数设置为 10
- 新增 migrations/001_users.up.sql:创建 users 表和 refresh_tokens 表
- 新增 migrations/001_users.down.sql:回滚脚本
- users 表包含 id, username, password_hash, created_at, updated_at
- refresh_tokens 表包含 id, user_id, token_hash, expires_at, created_at
- 添加必要的索引优化查询性能
- 添加 store 包导入
- 当 storage.driver 为 postgres 时创建 pgxpool
- 使用 defer 确保连接池正确关闭
- 添加日志记录连接状态
huanghaosheng merged commit c0972856c6 into develop 2026-06-14 16:50:25 +08:00
huanghaosheng deleted branch feature/user-model-phase1 2026-06-14 16:50:29 +08:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: XEngineers/CamTalk#93