Skip to content

Prisma migration#2

Merged
argahv merged 18 commits into
masterfrom
prisma-migration
May 30, 2026
Merged

Prisma migration#2
argahv merged 18 commits into
masterfrom
prisma-migration

Conversation

@argahv
Copy link
Copy Markdown
Owner

@argahv argahv commented May 30, 2026

Description

Brief description of the change.

Related Issue

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor
  • Other

Testing

  • cd frontend && npx tsc --noEmit passes
  • cd backend && PYTHONPATH=. python -m pytest tests/ -x -q passes
  • Tested with real API call (if applicable)

Checklist

  • My code follows the project code style
  • I have updated documentation accordingly
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective

argahv and others added 18 commits May 28, 2026 09:19
Add prisma-migration.md with full migration plan from asyncpg/sqlite3 to Prisma ORM.

Add prisma-schema-redesign.md with production-ready unified schema consolidating 15 models into 11, fixing 12 missing FK constraints, 9 cascade policies, and optimizing 8 indexes.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Extend the existing Prisma simulations model with v1 columns to support both schema generations in a single table:

- simulation_id (String?, unique): v1 TEXT PK alias for legacy lookups
- active_speaker_id (String?): v1 current speaker tracking
- state_json (Json?): v1 full SimulationState blob
- runtime_status (String, default 'idle'): v1 runtime state
- state_version (Int, default 0): v1 state version tracking

No new tables created. All v1 columns are nullable to avoid breaking v2-only rows.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add backend/app/database/prisma.py with complete Prisma ORM-based DatabaseBackend implementation (~1370 lines, 82 methods).

Covers all 43 abstract methods from base.py plus hasattr-discovered methods called from main.py:

- Stakeholder CRUD (create, get, update, list, delete, exists)
- Persona v2 (list, get, documents, evolution, research)
- Scenario templates (create with dual-write, migrate legacy, v2 listing)
- Simulations v1 (merged schema with state_json column)
- Simulations v2 (structured columns, turns, postmortems)
- New schema (create_new_simulation, participant management)
- Complex JOIN queries (turns with speaker names, simulation listing)
- State snapshots (create, query, retention pruning)
- Agent goals, semantic memory, analytics
- Agent detail queries (by ID, name, simulation history, turn history)
- Standalone get_agent_memories_by_id function for main.py import

Includes JSON coercion helpers for Pydantic string-to-dict roundtrip, PrismaJson wrapper for Jsonb fields, and compact JSON serialization (separators=(',',':')) for exact roundtrip fidelity.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
…dency

Update backend/app/database/__init__.py:

- Import PrismaBackend and get_agent_memories_by_id from .prisma
- Add DATABASE_TYPE=prisma option to factory (selects PrismaBackend)
- Add deprecation warnings for PostgresBackend and SQLiteBackend
- Expose get_agent_memories_by_id at module level

Add prisma-client>=0.15.0 to requirements.txt for the Python Prisma ORM client.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Remove dead v2_simulations and v2_turns tables (zero callers confirmed via grep). Rename v2_state_snapshots -> state_snapshots, v2_postmortems -> postmortems, v2_agent_goals -> agent_goals. Fix FK references to point to simulations.id with onDelete: Cascade. Remove 7 dead methods from prisma.py/postgres.py/sqlite.py.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1. Fix import in main.py:1446 - changed from .database.postgres to .database for get_agent_memories_by_id (was silently returning empty memories with PrismaBackend)
2. Add post-prisma-generate Base64 patch script at backend/scripts/patch_prisma_client.py + npm run generate command - fixes broken Python client after every prisma generate
3. Clean up invalid pool_size parameter from PrismaClient initialization - restores connectivity

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Production readiness fixes across all layers:

Backend:
- Configurable CORS via CORS_ORIGINS env var (config.py + main.py)
- Request body size limit middleware (10MB default, configurable)
- Added MAX_REQUEST_BODY_SIZE and CORS_ORIGINS env config

Frontend:
- Added app/error.tsx (client error boundary with retry)
- Added app/loading.tsx (global loading spinner)
- Added app/not-found.tsx (custom 404 page)
- Fixed silent .catch(()=>{}) error swallows in 4 pages
- Added empty state to personas page (no personas CTA)
- Added user-facing error display in analytics page
- Added output: 'standalone' to next.config.ts

Infrastructure:
- backend/Dockerfile (multi-stage Python build, Prisma codegen)
- frontend/Dockerfile (multi-stage Node build, standalone output)
- docker-compose.yml: full app stack (backend, frontend, worker-sim, worker-postmortem) joining infra

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add asyncio.Lock() for _active_simulations global dict to prevent race conditions under concurrent load.

- SSE double-execution guard: returns 409 Conflict if simulation is already running
- Auto-cleanup: removes completed simulations from active dict to prevent memory leak
- Lock-protected writes to _active_simulations in create handlers
- Fix renamed method references in all database backends to match abstract base

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- Added staggered animation to LeverageShifts component for smoother entry effects.
- Removed unused GSAP hooks and refactored StakeholderCard component for better performance and cleaner hover effects.
- Enabled animation for sentiment graph to enhance visual feedback.
- Updated status indicator colors in StrategicPlanPanel for better clarity.
- Adjusted animation duration in TranscriptStream for a more responsive feel.
- Expanded Tailwind CSS configuration to include new color utilities for better theming.
- Introduced a setup script to streamline environment setup and Docker service management.
…ario profiles

- personality_modulate() + PERSONALITY_EMOTION_MAP in internal_state.py
- PERSONALITY_SOCIAL_MAP + modulation wiring in social_physics.py
- ARCHETYPE_DELTA_MULTIPLIERS dict for all 6 archetypes in archetypes.py
- ScenarioProfile dataclass + 6 SCENARIO_PROFILES in new scenario_profile.py
- BehaviorEngine accepts scenario_type, personas; wires personality+archetype via context
- scenario_type added to all 6 template seed JSONs
- 116 tests pass including new modulation, archetype, and scenario tests
- Introduced SectionErrorBoundary for error handling in analytics sections.
- Added SimulationOutcomesSection for displaying simulation outcome data with charts.
- Implemented SocialDynamicsSection to visualize social dynamics data with various charts.
- Created TemporalTimelineSection to present a timeline of key moments in simulations.
- Updated index.ts to export new analytics components.
- Enhanced GraphLayout and TableLayout to use ExpandableText for content truncation.
- Modified EventLog and StrategicPlanPanel to include expandable text for better readability.
- Added API endpoint for fetching dashboard analytics data.
- Defined new types for dashboard analytics and related data structures in types.ts.
@argahv argahv merged commit 80447c8 into master May 30, 2026
0 of 2 checks passed
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.

1 participant