Skip to content

Instantly share code, notes, and snippets.

@rodrigoulisses
Created February 18, 2013 17:01
Show Gist options
  • Save rodrigoulisses/4978851 to your computer and use it in GitHub Desktop.
Save rodrigoulisses/4978851 to your computer and use it in GitHub Desktop.
class RemovePersonIdAndAddIndividualIdInToEmployee < ActiveRecord::Migration
def change
add_column :compras_employees, :individual_id, :integer
add_index :compras_employees, :individual_id
add_foreign_key :compras_employees, :unico_individuals,
:column => :individual_id
execute <<-SQL
UPDATE compras_employees AS ce
SET individual_id = (SELECT personable_id
FROM unico_people
WHERE id = ce.person_id and personable_type = "Individual")
SQL
remove_column :compras_employees, :person_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment