# How to Remove a Column with Zero Downtime in Ruby on Rails

DevFeed: [How to Remove a Column with Zero Downtime in Ruby on Rails](<https://devfeed.tech/articles/how-to-remove-a-column-with-zero-downtime-in-ruby-on-rails-21062.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2016/02/07/how-to-remove-a-column-with-zero-downtime-in-ruby-on-rails/>)

Published: 2016-02-07T12:00:00Z

Content type: tutorial

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Object-relational mapping](<https://devfeed.tech/topics/orm.md>), [Database](<https://devfeed.tech/topics/database.md>), [Persistence](<https://devfeed.tech/topics/persistence.md>), [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Deployment](<https://devfeed.tech/topics/deployment.md>), [Continuous integration](<https://devfeed.tech/topics/continuous-integration.md>)

Tags: [activerecord](<https://devfeed.tech/tags/activerecord.md>), [continuous-deployment](<https://devfeed.tech/tags/continuous-deployment.md>), [continuous-integration](<https://devfeed.tech/tags/continuous-integration.md>), [database](<https://devfeed.tech/tags/database.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [orm](<https://devfeed.tech/tags/orm.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [ruby-on-rails](<https://devfeed.tech/tags/ruby-on-rails.md>), [uptime](<https://devfeed.tech/tags/uptime.md>)

## AI overview

A tutorial explains how removing a database column affected production Ruby on Rails applications before Ruby on Rails 4.0.0, focusing on ORM behavior, uptime, and the multi-phase deployment process used to avoid downtime.

## Source excerpt

For a production Ruby on Rails application, uptime is paramount. Altering the structure of an application's persistence layer is an operation that competes directly with uptime. Specifically, removing a table column within a relational database causes issues with the ActiveRecord ORM (the default relational mapping within a Ruby on Rails application). However, this particular pain point has been removed as of Ruby on Rails 4.0.0, saving developers a lot of headache and greatly reducing the need for structural change coordination. Old and Busted To demonstrate the problem, a simple Ruby on Rails 3.2 application is created with a User model: class User < ActiveRecord::Base end Supporting the User model is a PostgreSQL database table created with a migration: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :first_name t.string :last_name t.string :email t.timestamps null: false end end end To ensure this application has as close to 100% uptime as possible, it can be assumed that it is behind some kind of pre-loader. As in, when code is deployed, existing requests are given time to complete before new requests are shepherded over to the new version of the code. In a Ruby on Rails 3.2 application, a problem will arise when a column is removed from the database and the ORM does not have time to restart. In this case, even the pre-loader will not save an application from throwing an error about the missing column. To emulate this problem, a rails console is run in the production environment and a User is created: RACK_ENV=production rails console > User.create(first_name: 'test', last_name: 'test') # => #<User id: 1, first_name: "test", last_name: "test", email nil, created_at: "2016-02-07 21:03:26", updated_at: "2016-02-07 21:03:26"> In parallel, the psql command line client is used to connect to the same production database used by this server, all still running locally. Within this psql prompt, the email column from the users t