change TEXT columns back to TEXT

mysql changes the type of TEXT columns to MEDIUMTEXT with "CONVERT TO",
but we don't want this, so change this columns back to TEXT.

see: https://bugs.mysql.com/bug.php?id=31291
This commit is contained in:
Benjamin Neff 2015-04-19 03:19:40 +02:00
parent f4fd77fa7c
commit 4be8a0bed9

View file

@ -25,7 +25,12 @@ 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}` CONVERT TO CHARACTER SET #{encoding} COLLATE #{collation}"
modify_text_columns = columns(table).select {|column| column.type == :text }.map {|column|
"MODIFY `#{column.name}` TEXT #{'NOT' unless column.null } NULL#{" DEFAULT '#{column.default}'" if column.has_default?}"
}.join(", ")
execute "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET #{encoding} COLLATE #{collation}#{", #{modify_text_columns}" unless modify_text_columns.empty?};"
end
end