Skip to content

Conversation

MoonIRL
Copy link

@MoonIRL MoonIRL commented Aug 28, 2025

本次提交为应用增加了 PostgreSQL 作为新的数据库后端选项,与现有的 MySQL 和 SQLite 并行。

主要变更包括:

  • ⚙️ 在 .env.exampleapp/config/config.py 中添加了 PostgreSQL 相关的配置项和验证逻辑。
  • 🔗 更新了 app/database/connection.py 以处理 PostgreSQL 数据库连接。
  • 📦 在 requirements.txt 中添加了 asyncpgpsycopg2-binary 依赖。
  • 🐳 在 docker-compose.yml 中添加了 postgres 服务,并创建了新的 docker-compose.build.yml 用于本地构建和开发。
  • ⏰ 调整了 app/database/models.py 中的时间戳处理,统一使用带时区的 UTC 时间,以增强跨数据库的兼容性。
  • 🔧 修复了 app/config/config.pysync_initial_settings 函数在 sqlite 环境下的时间戳处理问题。

本次提交为应用增加了 PostgreSQL 作为新的数据库后端选项,与现有的 MySQL 和 SQLite 并行。

主要变更包括:
- ⚙️ 在 `.env.example` 和 `app/config/config.py` 中添加了 PostgreSQL 相关的配置项和验证逻辑。
- 🔗 更新了 `app/database/connection.py` 以处理 PostgreSQL 数据库连接。
- 📦 在 `requirements.txt` 中添加了 `asyncpg` 和 `psycopg2-binary` 依赖。
- 🐳 在 `docker-compose.yml` 中添加了 `postgres` 服务,并创建了新的 `docker-compose.build.yml` 用于本地构建和开发。
- ⏰ 调整了 `app/database/models.py` 中的时间戳处理,统一使用带时区的 UTC 时间,以增强跨数据库的兼容性。
- 🔧 修复了 `app/config/config.py` 中 `sync_initial_settings` 函数在 `sqlite` 环境下的时间戳处理问题。
@MoonIRL
Copy link
Author

MoonIRL commented Sep 1, 2025

services:
  gemini-balance:
    build: .
    container_name: gemini-balance-local
    restart: unless-stopped
    ports:
      - "8800:8000"
    env_file:
      - .env
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test:
        [
          "CMD-SHELL",
          'python -c "import requests; exit(0) if requests.get(''http://localhost:8000/health'').status_code == 200 else exit(1)"',
        ]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 10s

  postgres:
    image: postgres:15
    container_name: gemini-balance-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${PGSQL_DATABASE}
      POSTGRES_USER: ${PGSQL_USER}
      POSTGRES_PASSWORD: ${PGSQL_PASSWORD}
    volumes:
      - ./pgsql_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${PGSQL_USER} -d ${PGSQL_DATABASE}"]
      interval: 10s # 每隔10秒检查一次
      timeout: 5s # 每次检查的超时时间为5秒
      retries: 3 # 重试3次失败后标记为 unhealthy
      start_period: 30s # 容器启动后等待30秒再开始第一次健康检查
DATABASE_TYPE=pgsql
# --- PostgreSQL 配置  ---
PGSQL_HOST=postgres
PGSQL_PORT=5432
PGSQL_USER=postgres
PGSQL_PASSWORD=postgres
PGSQL_DATABASE=default_db

API_KEYS=[ ]
ALLOWED_TOKENS=["st-123456"]
TZ=Asia/Shanghai

@MoonIRL
Copy link
Author

MoonIRL commented Sep 1, 2025

pgsql mysql sqlite 都是可以正常使用的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant