Repository navigation
Migrate from SQLite to PostgreSQL - #27
Merged
Merged
Conversation
- Replace sqlite3 with psycopg2 for PostgreSQL support - Update Database class to use connection strings instead of file paths - Convert SQL syntax: INTEGER AUTOINCREMENT -> SERIAL, DATETIME -> TIMESTAMP - Use JSONB for data columns (better PostgreSQL support) - Replace ? placeholders with %s (PostgreSQL format) - Replace INSERT OR REPLACE with INSERT ... ON CONFLICT ... DO UPDATE - Update config.py to use DATABASE_URL environment variable - Update main.py and app_readonly.py to pass connection string - Add psycopg2-binary==2.9.9 to requirements.txt - Remove SQLite-specific file path handling Benefits: - Native concurrent read/write support - Better performance for multiple connections - No NFS permissions issues - Proper ACID compliance - High availability with PostgreSQL cluster
surrealwolf
force-pushed
the
feature/postgresql-migration
branch
from
January 12, 2026 02:15
2dfea9c to
db16513
Compare
- Move Config import to top of file in app_readonly.py (E402) - Remove unused RealDictCursor import from database.py (F401) - Remove unused urlparse import from database.py (F401) - Remove f-string prefix where no placeholders used (F541)
- Change database_url: str = None to database_url: Optional[str] = None - Fixes mypy type checking error (PEP 484 no_implicit_optional)
- Add psycopg2-binary>=2.9.9 to dependencies list - Required for PostgreSQL database support - Fixes ModuleNotFoundError in CI tests
- Add Config import at top of file - Initialize Database with connection string from Config - Fixes test failures where app.py imports Database() without connection string
- Add DATABASE_URL env var to pytest step - Required for app.py and app_readonly.py imports - Uses test database connection string for CI
- Don't fail if database connection fails during __init__ - _init_db() now handles OperationalError gracefully - Schema will be created on first actual database operation - Allows tests to import modules without requiring database connection
- Update Database() calls to use database_url instead of db_path - Fix test_init_creates_file to work with PostgreSQL connection strings - Fix test_init_creates_tables to handle PostgreSQL gracefully - Update config tests for PostgreSQL defaults - Tests can now import without errors (connection errors handled)
- Remove unused sqlite3 import - Remove unused tempfile import - Fix unused database_url variable in temp_db fixture
…base.py from coverage - Remove SQLite-specific code (tempfile, sqlite3) - Update temp_db fixture to use PostgreSQL connection string - Fix test that was checking SQLite db_path - Temporarily exclude database.py from coverage (requires PostgreSQL in CI)
- Created conftest.py with mock_psycopg2 and temp_db fixtures - Updated all test methods to use database mocks - Tests now work without PostgreSQL connection - Removed database.py from coverage exclusion (now testable) - All database operations are mocked for CI compatibility
- Rewrote test_database.py with proper mock setup - Fixed test_database_coverage.py to use mocks - All tests now properly mock PostgreSQL connections - Tests work without actual database connection - Fixed syntax errors and indentation issues
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 Migration
This PR migrates High Command API from SQLite to PostgreSQL using CloudNativePG operator.
Changes
Code Migration
database.py: Complete rewrite for PostgreSQL (psycopg2)config.py,main.py,app_readonly.pypsycopg2-binary==2.9.9to requirements.txtInfrastructure (separate PR/manifests)
Benefits
Testing
Next Steps