Migrations
Learn how to manage database schema changes
The prisma/migrations folder stores migration files that track changes to your database schema (e.g., adding tables or fields). Prisma’s migration commands synchronize your schema.prisma with your Supabase database, ensuring consistency between your code and database structure.
Running Migrations
Update Your Schema
- Modify
schema.prismato add or change models (e.g., adding aPostmodel or a new field to theEvent).
Create a Migration
- Generate a new migration to reflect schema changes:
npx prisma migrate dev --name migration-name- Replace
migration-namewith a descriptive name (e.g.,add-post-model). This creates a migration file inprisma/migrationsand applies it to your Supabase database.
Apply Migrations in Production
- For production, use:
npx prisma migrate deploy- This applies pending migrations without generating new ones, ensuring your Supabase database aligns with your schema.
Verify Changes
- Use Supabase’s dashboard or a SQL client to confirm the schema updates (e.g., new tables or columns).
- Test your application to ensure queries work as expected.
Notes
- Environment Variables: Ensure
DATABASE_URLis set in both development and production environments. For production, configure it in your deployment platform (e.g., Vercel). - Backup Your Database: Before running migrations, back up your Supabase database via the dashboard to avoid data loss in case of errors.
- Conflict Resolution: If migrations fail due to schema conflicts, reset your database with
npx prisma migrate reset(use cautiously, as it drops and recreates the database). - Version Control: Commit migration files in
prisma/migrationsto track schema history, but never commit.envfiles with sensitiveDATABASE_URLvalues.
By following these steps, you can set up, connect, and manage your Supabase PostgreSQL database with Prisma ORM, keeping your Plainform project’s data layer robust and scalable.
For further details, consult the Supabase Database Overview or Prisma Documentation.
How is this guide ?
Last updated on