Skip to content
Extraits de code Groupes Projets
Valider f4fd77fa rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

use "CONVERT TO" to change the encoding for the table and all character columns

parent 2613896c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -25,24 +25,8 @@ class SetMysqlToUnicodeMb4 < ActiveRecord::Migration
execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET #{encoding} COLLATE #{collation};"
tables.each do |table|
execute "ALTER TABLE `#{table}` CHARACTER SET = #{encoding} COLLATE #{collation}"
execute "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET #{encoding} COLLATE #{collation}"
end
character_columns.each do |table, columns|
columns.each do |column|
execute "ALTER TABLE `#{table}` CHANGE `#{column.name}` `#{column.name}` #{column.sql_type} CHARACTER SET #{encoding} COLLATE #{collation} #{column.null ? 'NULL' : 'NOT NULL'} #{"DEFAULT '#{column.default}'" if column.has_default?};"
end
end
end
def character_columns
# build a hash with all the columns that contain characters
@character_columns ||= Hash[tables.map {|table|
col = columns(table)
.select {|column| column.type == :string || column.type == :text }
next if col.empty?
[table, col]
}.compact]
end
def shorten_indexes
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter