Does Netlify’s rollback automatically revert external database schema changes?
0 reputation · 09 Aug 2021, 11:24 UTC
0 reputation · 09 Aug 2021, 11:24 UTC
Goal: Determine whether a Netlify production rollback can safely revert an external database schema that was altered by a serverless function during the original deploy, so that the rolled‑back code and the database remain compatible without manual intervention.
Constraints: Netlify treats each deploy as an immutable snapshot; rolling back restores only the code, functions and static assets, leaving any schema changes made to an external database untouched. Because Netlify does not provide built‑in migration management or a rollback hook that invokes a down migration, developers must rely on their own tooling (e.g., Prisma, TypeORM) to compensate, and it is unclear if any configuration or feature can automate this safety net.
Can Netlify be configured to trigger a down migration automatically when a rollback occurs? Does Netlify provide an event or API that allows a migration tool to run compensating scripts during a rollback? Which existing Netlify features, if any, could be combined to achieve schema‑safe rollbacks without manual steps?
34775 reputation · 09 Aug 2021, 19:48 UTC
Netlify rollbacks are strictly application-layer operations. When you roll back a deploy, Netlify restores the static assets, serverless functions, and environment variables associated with a previous deploy ID. It has no visibility into, or control over, external data stores. Any schema changes executed by a serverless function or build script during a deployment are permanent side effects that persist regardless of which code version is currently active.
Because Netlify treats deploys as immutable snapshots of the application but not the infrastructure, a mismatch occurs during a rollback: the code reverts to version A, but the database remains at version B. If version A is not forward-compatible with the schema changes introduced in version B, the application will likely encounter runtime errors or data corruption.
Netlify does not currently provide a native "on-rollback" hook or a specific API event that triggers when a user manually reverts a production deploy via the UI. Consequently, you cannot configure Netlify to automatically invoke a "down" migration script from tools like Prisma or TypeORM during a rollback.
To achieve schema-safe deployments without manual intervention during a crisis, consider these architectural patterns:
To verify this behavior in your own environment:
Diagnostic Detail: Are you currently executing migrations during the build step or via a serverless function triggered after deployment? This distinction determines whether you can use build-plugin hooks to manage the "up" migration, though it does not solve the "down" migration problem.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.