Skip to content

Instantly share code, notes, and snippets.

@iberianpig
Last active August 29, 2015 14:15
Show Gist options
  • Save iberianpig/530f08af02cb41befca5 to your computer and use it in GitHub Desktop.
Save iberianpig/530f08af02cb41befca5 to your computer and use it in GitHub Desktop.
db/schemaを読み取って、default charset/collation, 既存DBのcharset/collationを変換するとき用。migrationファイルのchangeメソッドに使う。
class ChangeCollationOption < ActiveRecord::Migration
def up
execute "ALTER TABLE access_counters DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE access_counters CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE access_tokens DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE access_tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE activities DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE activities CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE admin_featured_users DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE admin_featured_users CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE air_bnb_campaign20140707s DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE air_bnb_campaign20140707s CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE authentications DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE authentications CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE bookmarks DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE bookmarks CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE categories DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE categories CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE category_maps DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE category_maps CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE category_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE category_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE checkin_locations DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE checkin_locations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE cities DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE cities CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE comments DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE continents DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE continents CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE countries DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE countries CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE country_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE country_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE crawl_logs DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE crawl_logs CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE delayed_jobs DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE delayed_jobs CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE device_tokens DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE device_tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE employees DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE employees CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE favorites DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE favorites CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE likes DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE likes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE meta_tags DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE meta_tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE meta_templates DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE meta_templates CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE notifications DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE notifications CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE official_informations DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE official_informations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE provider_categories DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE provider_categories CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spam_reports DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spam_reports CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spot_categories DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spot_categories CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spot_routes DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spot_routes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spot_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spot_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spots DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE spots CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE state_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE state_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE states DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE states CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE taggings DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE taggings CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tags DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tripnote_friends DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tripnote_friends CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tripnote_total_rank_histories DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tripnote_total_rank_histories CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tripnotes DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE tripnotes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_friends DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_friends CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_photos DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_photos CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_reviews DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_reviews CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_total_rank_histories DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE user_total_rank_histories CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE users DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
execute "ALTER TABLE users CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
end
def down
execute "ALTER TABLE access_counters DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE access_counters CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE access_tokens DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE access_tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE activities DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE activities CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE admin_featured_users DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE admin_featured_users CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE air_bnb_campaign20140707s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE air_bnb_campaign20140707s CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE authentications DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE authentications CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE bookmarks DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE bookmarks CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE categories DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE categories CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE category_maps DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE category_maps CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE category_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE category_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE checkin_locations DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE checkin_locations CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE cities DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE cities CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE comments DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE continents DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE continents CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE countries DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE countries CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE country_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE country_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE crawl_logs DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE crawl_logs CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE delayed_jobs DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE delayed_jobs CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE device_tokens DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE device_tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE employees DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE employees CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE favorites DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE favorites CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE likes DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE likes CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE meta_tags DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE meta_tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE meta_templates DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE meta_templates CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE notifications DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE notifications CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE official_informations DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE official_informations CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE provider_categories DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE provider_categories CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spam_reports DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spam_reports CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spot_categories DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spot_categories CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spot_routes DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spot_routes CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spot_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spot_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spots DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE spots CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE state_translations DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE state_translations CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE states DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE states CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE taggings DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE taggings CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tags DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tripnote_friends DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tripnote_friends CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tripnote_total_rank_histories DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tripnote_total_rank_histories CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tripnotes DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE tripnotes CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_friends DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_friends CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_photos DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_photos CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_reviews DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_reviews CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_total_rank_histories DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE user_total_rank_histories CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE users DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
execute "ALTER TABLE users CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment