Add Postgres support with SQLite backward compatibility #77
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/pal-e-api!77
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "76-postgres-code-changes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds Postgres (CNPG) support to pal-e-docs while maintaining full SQLite backward compatibility for local development. When
PALDOCS_DATABASE_URLis set, the app uses Postgres; otherwise it falls back toPALDOCS_DATABASE_PATH(SQLite). This is PR 1 of 2 -- code changes only, no infrastructure swap.Changes
src/pal_e_docs/config.py: Addeddatabase_url: str | None = Nonefield (maps toPALDOCS_DATABASE_URLenv var)src/pal_e_docs/database.py: Rewrote engine creation to prefer Postgres URL, fallback to SQLite; SQLite pragmas only apply when dialect is sqlitealembic/env.py: Updated to usedatabase_urlwhen available for migrationsalembic/versions/54714bc57fbe_initial_schema.py: Replacedsa.text('(CURRENT_TIMESTAMP)')withsa.func.now()alembic/versions/a1b2c3d4e5f6_add_repos_table.py: Same CURRENT_TIMESTAMP fixalembic/versions/b2c3d4e5f6a7_add_users_table.py: Same fix + replacedsa.text('1')withsa.true_()for boolean defaultalembic/versions/c3d4e5f6a7b8_add_project_is_public_and_page_note_fk.py: Replacedsa.text('1')withsa.true_()pyproject.toml: Addedpsycopg2-binary>=2.9dependencyscripts/migrate_sqlite_to_postgres.py: New data migration script (SQLite dump -> Postgres load + sequence reset)Test Plan
Review Checklist
Related Notes
plan-2026-02-26-tf-modularize-postgres-- the plan this implements (Phase 3)- Add database_url field to Settings (PALDOCS_DATABASE_URL env var) - Update database.py to use Postgres when database_url is set, fallback to SQLite - Update alembic/env.py to respect database_url for migrations - Replace SQLite-specific sa.text('(CURRENT_TIMESTAMP)') with sa.func.now() - Replace SQLite-specific sa.text('1') with sa.true_() - Add psycopg2-binary dependency - Add data migration script (scripts/migrate_sqlite_to_postgres.py) Closes #76 (PR 1 of 2) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>