Migrations
Migrations let you evolve your database schema over time. Each migration has anup (apply) and down (rollback) function, and Prism tracks which migrations have been applied in a _prism_migrations table.
Defining Migrations
Migration Definitions
Running Migrations
1
Create a Migrator
2
Run Pending Migrations
3
Check Status
Prism automatically creates a
_prism_migrations table to track applied migrations.Rolling Back
Rollback Last Migration
Migration Workflow
A typical workflow for adding a new feature:Adding Comments Feature
Server Startup Pattern
Migrate on Boot
Best Practices
Name migrations descriptively
Name migrations descriptively
Use names like
create_users, add_user_avatar, create_comments_index so you can tell what each migration does at a glance.Always write down migrations
Always write down migrations
Even if you think you won’t need to roll back, having a
down function makes development much smoother.Test migrations against a copy
Test migrations against a copy
Before running migrations in production, test them against a copy of your production database to catch issues early.
Keep migrations small
Keep migrations small
Each migration should do one thing. It’s better to have 10 small migrations than one giant one.