Prisma Migrations Blueprint
Manage database schema versioning and evolution with safe migrations
| Feature | prisma-migrations |
| Category | Data |
| Version | 1.0.0 |
| Tags | migrations, database, schema-evolution, deployment, versioning |
| YAML Source | View on GitHub |
| JSON API | prisma-migrations.json |
Actors
| ID | Name | Type | Description |
|---|---|---|---|
developer | Developer | human | |
ci_cd_pipeline | CI/CD Pipeline | system | |
migrations_engine | Migrations Engine | system | |
database | Database | external |
Fields
| Name | Type | Required | Label | Description |
|---|---|---|---|---|
command | select | Yes | Migration Command | |
migration_name | text | No | Migration Name | |
create_only | boolean | No | Create Only (Don’t Apply) | |
force_reset | boolean | No | Force Reset (Destructive) |
States
State field: migration_state
Values:
| State | Initial | Terminal |
|---|---|---|
pending | Yes | |
applied | ||
failed | ||
conflict |
Rules
- development: migrate dev: create from schema changes, apply, regenerate client, Creates safe migration using shadow database, Auto-detects data loss and prompts for confirmation, Regenerates Prisma Client with new types
- production: migrate deploy: apply pending migrations in order, Requires explicit –force for destructive operations, All migrations applied atomically, Prevents deployment if pending migrations exist
- safety: Shadow database validates changes before applying, Automatic detection of schema conflicts, migrate resolve for conflict resolution, Data loss warnings before destructive operations
Outcomes
Migration_created (Priority: 1)
Given:
- command is migrate_dev
- Schema has changes since last migration
Then:
- Migration SQL file created with timestamp
- migration.created event emitted
Result: Migration SQL file generated
Migration_applied (Priority: 2) | Transaction: atomic
Given:
- Migration SQL is valid
- Database constraints can be satisfied
Then:
- Migration marked as applied
- migration.applied event emitted
Result: Migration executed; schema updated
Client_regenerated (Priority: 3)
Given:
- Migration applied successfully
Then:
- client.generated event emitted
Result: Prisma Client regenerated with new types
Migration_conflict (Priority: 10) — Error: MIGRATION_CONFLICT
Given:
- Two migrations from same base state both applied
Then:
- emit_event event:
migration.conflict
Result: Error: run prisma migrate resolve
Data_loss_warning (Priority: 11) — Error: DATA_LOSS_DETECTED
Given:
- Migration would drop columns or data
- User has not confirmed data loss
Result: Error: confirm with –accept-data-loss flag
Errors
| Code | Status | Message | Retry |
|---|---|---|---|
MIGRATION_CONFLICT | 409 | Migrations {a} and {b} conflict. Run: prisma migrate resolve | No |
DATA_LOSS_DETECTED | 400 | This migration removes data. Confirm with –accept-data-loss | No |
MIGRATION_FAILED | 500 | Migration failed: {error} | No |
DATABASE_UNREACHABLE | 503 | Could not connect to database | No |
Events
| Event | Description | Payload |
|---|---|---|
migration.created | Migration file created | name, timestamp, changes |
migration.applied | Migration applied to database | name, applied_at, duration_ms |
migration.conflict | Migration conflict detected | migration_a, migration_b |
client.generated | Prisma Client regenerated | timestamp, type_count |
Related Blueprints
| Feature | Relationship | Reason |
|---|---|---|
| prisma-schema | required | Schema changes drive migrations |
| prisma-crud | required | Migrations create tables for CRUD operations |
AGI Readiness
Goals
Reliable Prisma Migrations
Manage database schema versioning and evolution with safe migrations
Success Metrics:
| Metric | Target | Measurement |
|---|---|---|
| data_accuracy | 100% | Records matching source of truth |
| duplicate_rate | 0% | Duplicate records detected post-creation |
Constraints:
- performance (non-negotiable): Data consistency must be maintained across concurrent operations
Autonomy
Level: supervised
Human Checkpoints:
- before transitioning to a terminal state
Escalation Triggers:
error_rate > 5
Tradeoffs
| Prefer | Over | Reason |
|---|---|---|
| data_integrity | performance | data consistency must be maintained across all operations |
Coordination
Protocol: orchestrated
Consumes:
| Capability | From | Fallback |
|---|---|---|
prisma_schema | prisma-schema | degrade |
prisma_crud | prisma-crud | degrade |
Safety
| Action | Permission | Cooldown | Max Auto |
|---|---|---|---|
| migration_created | supervised | - | - |
| migration_applied | autonomous | - | - |
| client_regenerated | autonomous | - | - |
| migration_conflict | autonomous | - | - |
| data_loss_warning | autonomous | - | - |