Skip to content

Commit

Permalink
change TEXT columns back to TEXT
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SuperTux88 committed Apr 19, 2015
1 parent f4fd77f commit 4be8a0b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb
Expand Up @@ -25,7 +25,12 @@ def change_encoding(encoding, collation)
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

Expand Down

0 comments on commit 4be8a0b

Please sign in to comment.