Last active
June 30, 2021 19:16
-
-
Save TsaiKoga/84fdcc3573219c454f2d00deea52abf4 to your computer and use it in GitHub Desktop.
Ruby on Rails rename columns in bulk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RenameOldOrderAddressRelatedColumn < ActiveRecord::Migration | |
def up | |
change_table(:orders, :bulk => true) do |t| | |
t.rename :order_status_code_id, :state | |
t.remove :in_process | |
[:first_name, | |
:last_name, | |
:country, | |
:state].each do |column| | |
t.rename "shipping_#{column}", "origin_shipping_#{column}" | |
end | |
end | |
end | |
end | |
# generate: | |
#=> ALTER TABLE `orders` DROP `in_process`, CHANGE `shipping_first_name` `origin_shipping_first_name` varchar(50) DEFAULT NULL, CHANGE `shipping_last_name` `origin_shipping_last_name` varchar(50) DEFAULT NULL, CHANGE `shipping_country` `origin_shipping_country` varchar(255) DEFAULT NULL, CHANGE `shipping_state` `origin_shipping_state` varchar(255) DEFAULT NULL... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment