1 hour ago · Tech · 0 comments

Dropping a column from a database table is one of the simplest possible migrations, if you just look at the syntax. But if you run that migration in a large application used by a ton of users where taking the application down for maintenance is not an option, you may run into problems.One thing I didn't realize until researching this post: ActiveRecord caches each model's schema the first time the model is loaded, and in production, with eager loading on, that means the whole schema is effectively cached at boot.This matters because of the deploy order. The migration runs first, then the app server restarts onto the new schema. In between, there's a window where the old process is still serving traffic with its cached view of the schema. If a request comes in during that window and the migration dropped a column, the running app will try to SELECT or INSERT a column that no longer exists and you get errors in production.Rails provides a mechanism to handle this cleanly:…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.