Changing a column in the database

Public, Databases

harrylevine

Created: Oct 23, 2014     Updated: Oct 25, 2014


I only recommend doing this if you are rolling back just one migration. If there have been many migrations since the change that you want to make, be aware that there may be data issues depending on what has transpired since that migration.

I have a column in my database that I created that I need to change.

Here is the current migration file:

class AddPublicToNotes < ActiveRecord::Migration
  def change
    add_column :notes, :private, :boolean, default: false
  end
end

I want to change the name of the column from private to public:

class AddPublicToNotes < ActiveRecord::Migration
  def change
    add_column :notes, :public, :boolean, default: false
  end
end

In order for this change to work properly across all three of my databases (development, test, and production), I want to make sure that I do the renaming in a specific sequence.

class AddPublicToNotes < ActiveRecord::Migration
  def change
    add_column :notes, :public, :boolean, default: false
  end
end