Skip to content

Commit 25f426d

Browse files
authored
Merge pull request #559 from chetanr25/migrate_posgresql
Migrate from SQLite to PostgreSQL
2 parents c80717e + bd64543 commit 25f426d

6 files changed

Lines changed: 35 additions & 15 deletions

File tree

app/core/config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
DEFAULT_TEMPLATE_DIR = os.getenv("FIREFORM_TEMPLATE_DIR", "data/inputs")
2727

2828
# --- Database -------------------------------------------------------------
29-
# Keep the SQLite file in the user's home so it survives container rebuilds.
30-
_APP_HOME = Path(os.path.expanduser("~")) / ".fireform"
31-
_APP_HOME.mkdir(parents=True, exist_ok=True)
32-
DB_PATH = Path(os.getenv("FIREFORM_DB_PATH", _APP_HOME / "fireform.db"))
33-
DATABASE_URL = f"sqlite:///{DB_PATH}"
29+
DATABASE_URL = os.getenv(
30+
"DATABASE_URL",
31+
"postgresql://fireform:fireform@localhost:5432/fireform",
32+
)
3433
DB_ECHO = os.getenv("FIREFORM_DB_ECHO", "true").lower() == "true"
3534

3635
# --- External services ----------------------------------------------------

app/db/database.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
from app.core.config import DATABASE_URL, DB_ECHO
44

5-
engine = create_engine(
6-
DATABASE_URL,
7-
echo=DB_ECHO,
8-
connect_args={"check_same_thread": False},
9-
)
5+
engine = create_engine(DATABASE_URL, echo=DB_ECHO)
106

117

128
def get_session():

docker/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# --- App ------------------------------------------------------------------
44
APP_PORT=8000
55

6+
# --- Database -------------------------------------------------------------
7+
# Dev: postgres runs inside Docker Compose, no config needed.
8+
DATABASE_URL=postgresql://fireform:fireform@localhost:5432/fireform
9+
610
# --- Ollama ---------------------------------------------------------------
711
# Ollama runs in Docker with port mapped to host. App runs on host.
812
# Override to point at an external Ollama instance (e.g. a GPU server).

docker/dev/compose.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
services:
2+
postgres:
3+
image: postgres:17-alpine
4+
container_name: fireform-postgres
5+
environment:
6+
POSTGRES_USER: fireform
7+
POSTGRES_PASSWORD: fireform
8+
POSTGRES_DB: fireform
9+
volumes:
10+
- postgres_data:/var/lib/postgresql/data
11+
ports:
12+
- "127.0.0.1:5432:5432"
13+
networks:
14+
- fireform-network
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready -U fireform"]
17+
interval: 10s
18+
timeout: 5s
19+
retries: 5
20+
221
ollama:
322
image: ollama/ollama:latest
423
container_name: fireform-ollama
@@ -41,6 +60,8 @@ services:
4160
dockerfile: docker/dev/Dockerfile
4261
container_name: fireform-app
4362
depends_on:
63+
postgres:
64+
condition: service_healthy
4465
ollama:
4566
condition: service_healthy
4667
whisper:
@@ -49,19 +70,18 @@ services:
4970
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
5071
volumes:
5172
- ../..:/app
52-
- fireform_db:/data/db
5373
- fireform_uploads:/data/uploads
5474
ports:
5575
- "${APP_PORT:-8000}:8000"
5676
environment:
5777
- PYTHONUNBUFFERED=1
5878
- CUDA_VISIBLE_DEVICES=
5979
- PYTHONPATH=/app
80+
- DATABASE_URL=postgresql://fireform:fireform@postgres:5432/fireform
6081
- OLLAMA_HOST=${OLLAMA_HOST:-http://ollama:11434}
6182
- OLLAMA_TIMEOUT=${OLLAMA_TIMEOUT:-300}
6283
- OLLAMA_MODEL=${OLLAMA_MODEL:-qwen2.5:1.5b}
6384
- WHISPER_HOST=${WHISPER_HOST:-http://whisper:9000}
64-
- FIREFORM_DB_PATH=/data/db/fireform.db
6585
- FIREFORM_DATA_DIR=/data/uploads
6686
- FIREFORM_TEMPLATE_DIR=/data/uploads
6787
- FIREFORM_DB_ECHO=${FIREFORM_DB_ECHO:-true}
@@ -70,12 +90,12 @@ services:
7090
- fireform-network
7191

7292
volumes:
93+
postgres_data:
94+
driver: local
7395
ollama_data:
7496
driver: local
7597
whisper_models:
7698
driver: local
77-
fireform_db:
78-
driver: local
7999
fireform_uploads:
80100
driver: local
81101

docker/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
# Ensure data directories exist (volumes may be empty on first run)
5-
mkdir -p /data/db /data/uploads
5+
mkdir -p /data/uploads
66

77
# Run DB migrations / init before starting the server
88
python3 -m app.db.init_db

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fastapi
55
uvicorn
66
pydantic
77
sqlmodel
8+
psycopg2-binary
89
pytest
910
httpx
1011
numpy<2

0 commit comments

Comments
 (0)