Skip to main content
This workflow guides you through promoting schema changes across your environment pipeline. Start by developing and testing migrations locally, then systematically deploy them through dev, UAT, and staging environments before reaching production. Each environment serves as a validation checkpoint, ensuring your schema changes are safe and reliable before they impact your production database.
1

Develop Feature Locally

Work on your feature in your development environment, making database changes as needed.
2

Capture Development Schema

Once your changes are complete and tested, dump the development database schema.
This creates a schema.sql file containing your complete schema definition.
3

Commit to Version Control

Add the schema file to your repository and create a pull request.
The schema file serves as both documentation and the source of truth for migrations.
4

Preview Staging Changes

In your CI pipeline, you would automatically generate a plan.json as well as the human readable plan by running pgschema plan against your staging environment to show reviewers what changes will be applied.
This plan.json will later be used to deploy to both staging and production. Review the plan carefully to ensure the changes match your expectations.
5

Merge to Main Branch

After code review and approval, merge your changes to the main branch.
Both schema.sql and plan.json would be merged together and are now ready for deployment.
6

Deploy to Staging

Apply the schema changes to your staging environment using the plan.json.
If there have been concurrent schema changes since the plan was created, the apply will fail safely due to fingerprinting. In this case, regenerate the plan and try again.
7

Deploy to Production

After successful staging validation, apply changes to production using the same plan.json.
If the production schema has drifted from the staging schema (manual changes, hotfixes, etc.), the fingerprint will fail and the apply will be rejected. This prevents applying changes to an unexpected schema state.