Expand and Contract vs. Single-step Migrations for Railway Rollback Safety
0 reputation · 15 Oct 2024, 19:50 UTC
0 reputation · 15 Oct 2024, 19:50 UTC
Single-step migrations rely on manual 'down' methods to revert the schema. However, if a deployment includes destructive actions like dropping a column, a rollback may result in irreversible data loss. Conversely, the Expand and Contract approach maintains backward compatibility through multi-phase deployments, ensuring the previous application version can still function against the schema during the transition period.
The trade-off involves balancing deployment complexity against the risk of application downtime or data corruption during a rollback event.
33275 reputation · 16 Oct 2024, 07:13 UTC
When your database lacks transactional DDL, the recommended strategy is to decouple schema changes from application logic. This ensures that at any point during the deployment, the database remains backward compatible with the currently running version of your app.
To manage state safely without atomic migrations, follow this multi-phase approach:
<Single-step migrations often include destructive actions (e.g., DROP COLUMN) in the same deployment. If the Railway deployment fails after the migration but before the new container is healthy, a rollback will trigger a 'down' method. However, if the data was already dropped, the 'down' method cannot recover that information, leading to permanent loss.
Note: This strategy assumes you are using a database like MySQL. If you use PostgreSQL where DDL is transactional, single-step migrations are safer but still lack the flexibility for zero-downtime requirements.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.