This document outlines the workflow for managing database migrations using Prisma in a project.
-
Make Changes to the Schema:
- Modify the desired Prisma schema file to reflect the changes you want to make to the database schema.
- Ensure changes are made to the proper schema file based on the category of the schema change.
-
Run the Migration Command:
-
Execute the following command to create a migration:
yarn migrate
-
This command will:
- Validate the schema via
npx prisma validate
. - Create a migration file named after the current branch.
- Create a commit with the migration file.
- Push the commit to the branch.
- Validate the schema via
-
You will be prompted to enter a commit message. This is optional, and if you do not provide one, the default will be the name of the branch.
-
-
Review the Migration:
- Note that running the migration command only creates the migration file. It does not apply the migration to the database.
- This allows for the migration to be reviewed in a pull request.
-
Pipeline Validation:
- After pushing the migration, a pipeline will run to validate the schema using
prisma validate
. - The validation ensures that the schema changes are correct and do not introduce any issues.
- After pushing the migration, a pipeline will run to validate the schema using
-
Pull Request Approval:
- Once the PR is created, it needs to be reviewed and approved.
- Only upon approval can the PR be merged into the UAT branch.
-
Processing the Migration:
- When the PR is merged into the UAT branch, a pipeline will run to apply the migration to the UAT database.
- The same process occurs when merging into the staging and production branches, ensuring that the migration is applied to the respective databases.
- Schema Changes: Modify schema file.
- Create Migration: Run
yarn migrate
. - Review Migration: Migration file is created, not applied.
- Pipeline Validation: Schema validated using
prisma validate
. - Approval: PR reviewed and approved.
- Apply Migration: Merged into UAT, staging, and production to apply the migration.
By following this workflow, we ensure that database schema changes are reviewed, validated, and applied in a controlled and systematic manner.