Skip to content

Fix API seed connection error#26

Merged
platzhersh merged 1 commit intomainfrom
claude/fix-api-seed-connection-b5xvf
Jan 8, 2026
Merged

Fix API seed connection error#26
platzhersh merged 1 commit intomainfrom
claude/fix-api-seed-connection-b5xvf

Conversation

@platzhersh
Copy link
Owner

@platzhersh platzhersh commented Jan 8, 2026

The seed script was failing in Railway deployments because it tried to connect to the API before the API server was started. The Dockerfile runs migrations, then seeds, then starts the API - but the seed script expected the API to be running.

Changes:

  • Refactored seed_staging.py to use Prisma client directly instead of HTTP calls
  • Removed httpx dependency from seed script (now uses Prisma for all DB operations)
  • No longer requires API_URL environment variable
  • Updated CLAUDE.md documentation to reflect this change

Benefits:

  • Seed script now works in Railway deployment flow
  • Faster and more reliable (direct DB access vs HTTP calls)
  • No need to wait for API to be healthy before seeding
  • Cleaner separation of concerns

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated staging data seeding documentation to reflect that the API is no longer required during the seeding process.
  • Chores

    • Improved the staging data seeding process to use direct database operations, eliminating dependencies on the running API.

✏️ Tip: You can customize this high-level summary in your review settings.

The seed script was failing in Railway deployments because it tried to connect
to the API before the API server was started. The Dockerfile runs migrations,
then seeds, then starts the API - but the seed script expected the API to be
running.

Changes:
- Refactored seed_staging.py to use Prisma client directly instead of HTTP calls
- Removed httpx dependency from seed script (now uses Prisma for all DB operations)
- No longer requires API_URL environment variable
- Updated CLAUDE.md documentation to reflect this change

Benefits:
- Seed script now works in Railway deployment flow
- Faster and more reliable (direct DB access vs HTTP calls)
- No need to wait for API to be healthy before seeding
- Cleaner separation of concerns
@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

Walkthrough

The pull request refactors the staging data seeding script to use Prisma for direct database interactions instead of HTTP API calls. Function signatures updated to accept a Prisma client, and lifecycle management added for client connection handling. Documentation updated to reflect these changes.

Changes

Cohort / File(s) Summary
Documentation Updates
CLAUDE.md
Updated comment noting that staging data seeding uses Prisma directly and does not require the API to be running
Seeding Logic Refactoring
scripts/seed_staging.py
Replaced HTTP-based seeding (httpx) with Prisma client database operations. Updated should_seed(), create_patient(), create_vital_signs(), and seed_patient_with_vitals() function signatures to accept Prisma client. Added Prisma lifecycle management (create, connect, disconnect) in main(). Converted date/time fields to Prisma-compatible types and ensured model dump returns align with Prisma schema

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 Hops through the seedbed with joy and care,
No HTTP calls floating in the air,
Prisma now whispers to databases deep,
Staging data grows while the server sleeps! 🌱✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'Fix API seed connection error' is vague and misleading. The actual change is a refactoring from HTTP-based to Prisma-based database operations, not a fix to a connection error. Consider a more descriptive title like 'Refactor seed script to use Prisma client directly instead of HTTP API calls' to accurately reflect the main change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-api-seed-connection-b5xvf

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
scripts/seed_staging.py (1)

204-248: Add return type hint to main().

Per the coding guidelines, type hints are required everywhere. The function is missing its return type annotation.

Suggested fix
-async def main():
+async def main() -> None:
     """Main seeding function."""

The Prisma lifecycle management with try/finally is well-structured, ensuring db.disconnect() runs even if seeding fails.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e48730 and cb4231f.

📒 Files selected for processing (2)
  • CLAUDE.md
  • scripts/seed_staging.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Type hints required everywhere in Python code (enforced by mypy config)

Files:

  • scripts/seed_staging.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
Repo: platzhersh/open-cis PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-06T20:52:27.939Z
Learning: Prisma schema changes require running prisma generate and prisma migrate dev
📚 Learning: 2026-01-06T20:52:27.939Z
Learnt from: CR
Repo: platzhersh/open-cis PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-06T20:52:27.939Z
Learning: Prisma schema changes require running prisma generate and prisma migrate dev

Applied to files:

  • CLAUDE.md
📚 Learning: 2026-01-06T20:52:27.939Z
Learnt from: CR
Repo: platzhersh/open-cis PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-06T20:52:27.939Z
Learning: Seed synthetic data on Railway staging deployments when RAILWAY_ENVIRONMENT=staging is set

Applied to files:

  • CLAUDE.md
  • scripts/seed_staging.py
📚 Learning: 2026-01-06T20:52:27.939Z
Learnt from: CR
Repo: platzhersh/open-cis PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-06T20:52:27.939Z
Learning: Applies to api/src/**/*.py : Prisma client is async-only with asyncio interface

Applied to files:

  • scripts/seed_staging.py
🔇 Additional comments (6)
CLAUDE.md (1)

81-81: LGTM!

Documentation accurately reflects the refactored seed script behavior—Prisma direct access eliminates the API dependency.

scripts/seed_staging.py (5)

18-21: LGTM!

The sys.path manipulation to import from api/src is acceptable for a standalone seed script. The noqa: E402 comment appropriately suppresses the import-order lint warning.


38-63: LGTM!

Properly typed with db: Prisma and -> bool. The idempotent check using db.patient.count() is clean, and the fallback behavior on exception is appropriate for a seed script.


66-85: LGTM!

Type hints are present. The birth_date conversion logic correctly handles both string and date inputs. Using model_dump() for consistent dict output is appropriate.


88-109: LGTM!

Properly typed and follows the same pattern as create_patient. The datetime conversion is appropriate since the input originates from generate_realistic_vital_signs which uses UTC-aware datetimes.


163-201: LGTM!

Function signature correctly updated to accept the Prisma client. Return type tuple[dict | None, list[dict]] is properly annotated.

@platzhersh platzhersh merged commit 3734623 into main Jan 8, 2026
1 check passed
@platzhersh platzhersh deleted the claude/fix-api-seed-connection-b5xvf branch January 8, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments