Conversation
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
WalkthroughThe 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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
scripts/seed_staging.py (1)
204-248: Add return type hint tomain().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/finallyis well-structured, ensuringdb.disconnect()runs even if seeding fails.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CLAUDE.mdscripts/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.mdscripts/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.pathmanipulation to import fromapi/srcis acceptable for a standalone seed script. Thenoqa: E402comment appropriately suppresses the import-order lint warning.
38-63: LGTM!Properly typed with
db: Prismaand-> bool. The idempotent check usingdb.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_dateconversion logic correctly handles both string and date inputs. Usingmodel_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 fromgenerate_realistic_vital_signswhich 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.
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:
Benefits:
Summary by CodeRabbit
Release Notes
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.