feat: 🐘 新增 PostgreSQL 数据库支持#345
Open
MoonIRL wants to merge 1 commit into
Open
Conversation
本次提交为应用增加了 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` 环境下的时间戳处理问题。
Author
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 |
Author
|
pgsql mysql sqlite 都是可以正常使用的 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本次提交为应用增加了 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环境下的时间戳处理问题。