Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
db16513
Migrate from SQLite to PostgreSQL
surrealwolf Jan 12, 2026
84266da
fix: Resolve linting errors from CI
surrealwolf Jan 12, 2026
2327b1b
fix: Add Optional type hint for database_url parameter
surrealwolf Jan 12, 2026
0be1fa4
fix: Add psycopg2-binary to pyproject.toml dependencies
surrealwolf Jan 12, 2026
1f13560
fix: Update app.py to use PostgreSQL connection string
surrealwolf Jan 12, 2026
a2ea13e
fix: Set DATABASE_URL environment variable in CI tests
surrealwolf Jan 12, 2026
7283f08
fix: Make database initialization lazy and handle connection errors
surrealwolf Jan 12, 2026
ed8abab
fix: Initialize conn variable before try block in _init_db
surrealwolf Jan 12, 2026
7252c4f
fix: Update tests for PostgreSQL migration
surrealwolf Jan 12, 2026
512e4cb
fix: Complete test_init_creates_file fix for PostgreSQL
surrealwolf Jan 12, 2026
64be82d
fix: Remove unused imports from test_database.py
surrealwolf Jan 12, 2026
b159a3e
fix: Update test_database_coverage.py for PostgreSQL and exclude data…
surrealwolf Jan 12, 2026
5e5ba01
feat: Add comprehensive database mocking for tests
surrealwolf Jan 12, 2026
8950963
fix: Clean up test files and properly implement database mocking
surrealwolf Jan 12, 2026
bc3ce45
Fix lint errors: Remove unused imports from test files
surrealwolf Jan 12, 2026
45e5ab7
Fix lint error: Remove unused json import from conftest.py
surrealwolf Jan 12, 2026
6b56399
Restore original conftest helpers alongside database mocking fixtures
surrealwolf Jan 12, 2026
6babcb0
Fix failing database tests by configuring mock cursor return values
surrealwolf Jan 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
mypy src --ignore-missing-imports
- name: Run tests with coverage
run: pytest --cov=src --cov-report=xml --cov-report=term --cov-fail-under=80
env:
DATABASE_URL: "postgresql://test:test@localhost:5432/test_db"
- name: Upload coverage reports
uses: codecov/codecov-action@v5
with:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
"requests>=2.31.0",
"python-dotenv>=1.0.0",
"APScheduler>=3.10.4",
"psycopg2-binary>=2.9.9",
]

[project.optional-dependencies]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ uvicorn==0.24.0
requests==2.31.0
python-dotenv==1.0.0
APScheduler==3.10.4
psycopg2-binary==2.9.9
6 changes: 5 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, Query
from fastapi.middleware.cors import CORSMiddleware
from src.config import Config
from src.database import Database
from src.scraper import HellDivers2Scraper
from src.collector import DataCollector
Expand All @@ -13,7 +14,10 @@
logger = logging.getLogger(__name__)

# Initialize database and scraper
db = Database()
database_url = Config.DATABASE_URL
if not database_url:
raise ValueError("DATABASE_URL environment variable must be set")
db = Database(database_url)
scraper = HellDivers2Scraper()
collector = DataCollector(db, interval=300)

Expand Down
6 changes: 5 additions & 1 deletion src/app_readonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, Query
from fastapi.middleware.cors import CORSMiddleware
from src.config import Config
from src.database import Database
from src.scraper import HellDivers2Scraper

Expand All @@ -12,7 +13,10 @@
logger = logging.getLogger(__name__)

# Initialize database and scraper (for fallback reads only)
db = Database()
database_url = Config.DATABASE_URL
if not database_url:
raise ValueError("DATABASE_URL environment variable must be set")
db = Database(database_url)
scraper = HellDivers2Scraper()


Expand Down
4 changes: 2 additions & 2 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Config:
TESTING = False

# Database
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///helldivers2.db")
DATABASE_URL = os.getenv("DATABASE_URL", "")

# API Settings
API_TIMEOUT = 30
Expand Down Expand Up @@ -44,7 +44,7 @@ class TestingConfig(Config):
"""Testing configuration"""

TESTING = True
DATABASE_URL = "sqlite:///:memory:"
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://test:test@localhost:5432/test_db")
SCRAPE_INTERVAL = 60


Expand Down
Loading