Skip to content

Instantly share code, notes, and snippets.

@senny
Last active December 14, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senny/5019598 to your computer and use it in GitHub Desktop.
Save senny/5019598 to your computer and use it in GitHub Desktop.
rails 3-2-stable remove_column in migrations
THE SCHEMA CHANGES FROM:
ActiveRecord::Schema.define(:version => 0) do
create_table "my_table", :primary_key => "my_table_id", :force => true do |t|
t.integer "col_one"
t.string "col_two", :limit => 128, :null => false
end
end
TO:
ActiveRecord::Schema.define(:version => 0) do
create_table "my_table", :id => false, :force => true do |t|
t.integer "my_table_id"
t.integer "col_one"
end
end
require 'active_record'
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
ActiveRecord::Schema.define do
create_table "my_table", :primary_key => "my_table_id", :force => true do |t|
t.integer "col_one"
t.string "col_two", :limit => 128, :null => false
end
end
ActiveRecord::SchemaDumper.dump
ActiveRecord::Schema.define(version: 0) do
create_table "my_table", primary_key: "my_table_id", force: true do |t|
t.integer "col_one"
t.string "col_two", limit: 128, null: false
end
end
class RemoveColTwoFromMyTable < ActiveRecord::Migration
def up
remove_column :my_table, "col_two"
end
end
RemoveColTwoFromMyTable.migrate :up
ActiveRecord::SchemaDumper.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment