Safely Dropping Columns in Rails 0 ▲ Write Software Well 193 days ago · 6 min read1237 words · Tech · hide · Fediverse post 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:… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town