Skip to content

Instantly share code, notes, and snippets.

@agungyuliaji
Last active December 20, 2015 10:49
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 agungyuliaji/6118860 to your computer and use it in GitHub Desktop.
Save agungyuliaji/6118860 to your computer and use it in GitHub Desktop.
Postgres change column string to integer
class ChangeColumnOnMovementShipmentDvcaAndDvcu < ActiveRecord::Migration
def change
rename_column :movement_shipments, :dvca, :dvca_s
rename_column :movement_shipments, :dvcu, :dvcu_s
add_column :movement_shipments, :dvca, :decimal, default: 0
add_column :movement_shipments, :dvcu, :decimal, default: 0
MovementShipment.reset_column_information
MovementShipment.find_each { |c| c.update_attributes({
dvca: c.dvca_s,
dvcu: c.dvcu_s
}) }
remove_column :movement_shipments, :dvca_s
remove_column :movement_shipments, :dvcu_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment