diff --git a/Changelog.md b/Changelog.md index caef07077876c06ef8bfaa8bf8c1e02437b0ab83..32cb2fe8b95dc11b9b646badd54fc2964f6620ec 100644 --- a/Changelog.md +++ b/Changelog.md @@ -177,6 +177,7 @@ diaspora* no longer adds a `div.container` to wrap custom splash pages. This add * Prevent inserting posts into the wrong stream [#5838](https://github.com/diaspora/diaspora/pull/5838) * Update help section [#5857](https://github.com/diaspora/diaspora/pull/5857) [#5859](https://github.com/diaspora/diaspora/pull/5859) * Fix asset precompilation check in script/server [#5863](https://github.com/diaspora/diaspora/pull/5863) +* Convert MySQL databases to utf8mb4 [#5530](https://github.com/diaspora/diaspora/pull/5530) [#5624](https://github.com/diaspora/diaspora/pull/5624) [#5865](https://github.com/diaspora/diaspora/pull/5865) ## Features * Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105) diff --git a/db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb b/db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb index 9495e7f80d2f7b3ede9974ca1d950c07d5d87528..37dd9373effae539324b6ffa78bb46ad9642a638 100644 --- a/db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb +++ b/db/migrate/20150106050733_set_mysql_to_unicode_mb4.rb @@ -25,24 +25,13 @@ 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}" - 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 + 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(", ") - 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] + execute "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET #{encoding} COLLATE #{collation}#{", #{modify_text_columns}" unless modify_text_columns.empty?};" + end end def shorten_indexes