Skip to main content

Schema Updates

Steps to update the Prisma schema:

  • add your changes in the prisma.schema file
  • to execute commands, set your terminal to prisma package (packages/database/)
  • create migration file and apply: npx prisma migrate dev --name <name_of_migration>
    • if you're not sure how prisma will generate the script, you can add --create-only flag, then Prisma will create the migration script, but not apply it, you can modify the script and then apply it
  • to apply all the migrations locally npx prisma migrate dev
  • in case something went wrong, or you had to reset the schema (roll back the last change in the schema in the .schema file):
    • to reset DB: npm run db:reset
    • to seed DB: npm run db:seed
    • check status according to migration files: npx prisma migrate status
    • apply old migrations: npx prisma migrate resolve --applied <migration_name>
    • add new changes to schema -> run again script to create the new migration
  • for PROD environments or any other that we don't want to lose data, in order to apply schema update: npx prisma migrate deploy

Update Schema Locally

With time, the new schema updates will be coming, once you pull the code with the updated schema, you might have errors and not be able to build your project.

In order to fix it you should run those commands in /package/database/ directory:

  • npx prisma migrate status - show the migrations that are not applied to your local DB (*extra)
  • npx prisma migrate deploy - apply missing migrations to your local DB
  • npm run db:generate - generate Prisma Client package that is used by all the applications