Created
April 16, 2013 17:41
-
-
Save mrsweaters/5397928 to your computer and use it in GitHub Desktop.
Convert from latin1 to utf8 Charater Set
This file contains hidden or 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 UpdateEncoding < ActiveRecord::Migration | |
| def self.up | |
| database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database] | |
| execute 'ALTER DATABASE ' + database_name + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE categories CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE categories_posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE uploads CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE last_tweet_ids CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE schema_migrations CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| execute 'ALTER TABLE users CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' | |
| end | |
| def self.down | |
| execute 'ALTER DATABASE ' + database_name + ' DEFAULT CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE categories CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE categories_posts CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE comments CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE posts CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE uploads CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE last_tweet_ids CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE schema_migrations CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| execute 'ALTER TABLE users CONVERT TO CHARACTER SET latin1 COLLATE ISO-8859-1;' | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment