feat: 添加PostgreSQL支持并更新数据库配置
- 新增PostgreSQL服务支持,使用最新版17 - 更新Docker Compose配置以支持PostgreSQL和Redis - 修改数据库连接逻辑,支持PostgreSQL和SQLite - 更新文档以反映新的数据库配置和使用方法 - 优化数据模型,确保时间戳字段支持时区
This commit is contained in:
@@ -1,6 +1,32 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# PostgreSQL 数据库(使用最新版 17)
|
||||
postgres:
|
||||
image: postgres:17-alpine
|
||||
container_name: life-echo-postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-life_echo}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
restart: always
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
networks:
|
||||
- life-echo-network
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
# Redis 服务(用于会话存储和 Celery 消息队列)
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
@@ -36,11 +62,12 @@ services:
|
||||
env_file:
|
||||
- .env.prod
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/life_echo
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
volumes:
|
||||
- ./life_echo.db:/app/life_echo.db
|
||||
restart: always
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
@@ -48,7 +75,7 @@ services:
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
start_period: 15s
|
||||
networks:
|
||||
- life-echo-network
|
||||
logging:
|
||||
@@ -68,11 +95,12 @@ services:
|
||||
env_file:
|
||||
- .env.prod
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/life_echo
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
volumes:
|
||||
- ./life_echo.db:/app/life_echo.db
|
||||
restart: always
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
api:
|
||||
@@ -96,9 +124,12 @@ services:
|
||||
# env_file:
|
||||
# - .env.prod
|
||||
# environment:
|
||||
# - DATABASE_URL=postgresql://postgres:postgres@postgres:5432/life_echo
|
||||
# - REDIS_URL=redis://redis:6379/0
|
||||
# restart: always
|
||||
# depends_on:
|
||||
# postgres:
|
||||
# condition: service_healthy
|
||||
# redis:
|
||||
# condition: service_healthy
|
||||
# networks:
|
||||
@@ -130,5 +161,7 @@ networks:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
driver: local
|
||||
redis_data:
|
||||
driver: local
|
||||
|
||||
Reference in New Issue
Block a user