Why use previews
- Test a change with real tables and rules without touching
staging. - Give a reviewer a working backend for a pull request’s preview deployment.
- Run automated tests against a clean environment every time.
- Try a risky migration somewhere disposable first.
Create one in Studio
- Project → Environments → New preview.
- Choose the environment to copy from (usually
developmentorstaging). - Give the ref: lowercase letters, digits and dashes, up to 48 characters, typically the branch name (
add-referrals). The preview is calledpr-<ref>unless you give it a name. - Choose how long it lives: 72 hours by default, from 1 hour to 30 days.
- Create. Studio shows its publishable and secret keys. Copy them now.
What a preview contains
Its two keys, a publishable key and a secret key, expire when the preview does.
Copied webhooks and schedules are live in the preview. If a webhook points at a real partner, or a schedule sends email, disable them in the preview or point them at test targets. Pause mail delivery in previews.
Create one from CI
The usual setup: when a pull request opens, CI creates a preview, seeds it, deploys the frontend preview against it, runs tests, and the preview expires on its own.
The source environment is the one in the address (
/envs/staging/previews), and the key used must be allowed to manage it. A preview with the same name already existing is refused with 409, so use a stable ref per pull request and delete or reuse it. If your plan’s environment limit is reached, creating a preview is refused.
Infrastructure as code can then deploy the branch’s own definitions to the preview, so it matches the branch rather than the source.
Seed it
A preview’s tables start empty. Seed what your tests need from CI, using the preview’s secret key:Clean up
A preview expires by itself: when its time is up, it and everything in it are removed. To remove it sooner (for example when the pull request closes), delete it from Project → Environments, or:Good practice
- Name previews after the branch, so it’s obvious which can go.
- Use test keys for any provider a preview’s flows call. Never a live payment key.
- Disable outbound webhooks in previews unless they point at test receivers.
- Never put real customer data in a preview.
- Keep the lifetime short and let CI recreate it.