Merge pull request #5624 from dimaursu/emoji
Add collation and config check
This commit is contained in:
commit
b991ffe455
3 changed files with 19 additions and 8 deletions
|
|
@ -33,8 +33,9 @@ series and run our comprehensive test suite against it.
|
||||||
The default for including jQuery from a CDN has changed. If you want to continue to include it from a CDN, please explicitly set the `jquery_cdn` setting to `true` in diaspora.yml.
|
The default for including jQuery from a CDN has changed. If you want to continue to include it from a CDN, please explicitly set the `jquery_cdn` setting to `true` in diaspora.yml.
|
||||||
|
|
||||||
## Change in database.yml
|
## Change in database.yml
|
||||||
For MySQL databases, replace `charset: utf8` with `encoding: utf8mb4` in the file `config/database.yml`. This is enables full UTF8 support (4bytes characters), including standard emoji characters. See `database.yml.example` for reference.
|
For MySQL databases, replace `charset: utf8` with `encoding: utf8mb4m` and change `collation` from `utf8_bin` to `utf8mb4_bin` in the file `config/database.yml`.
|
||||||
Also, do not forget to remove `collation: utf8_bin`. It will choose a compatible one automatically.
|
This is enables full UTF8 support (4bytes characters), including standard emoji characters.
|
||||||
|
See `database.yml.example` for reference.
|
||||||
Please make sure to stop Diaspora prior running this migration!
|
Please make sure to stop Diaspora prior running this migration!
|
||||||
|
|
||||||
## Experimental chat feature
|
## Experimental chat feature
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ mysql: &mysql
|
||||||
password: ""
|
password: ""
|
||||||
# socket: /tmp/mysql.sock
|
# socket: /tmp/mysql.sock
|
||||||
encoding: utf8mb4
|
encoding: utf8mb4
|
||||||
|
collation: utf8mb4_bin
|
||||||
|
|
||||||
postgres: &postgres
|
postgres: &postgres
|
||||||
adapter: postgresql
|
adapter: postgresql
|
||||||
|
|
|
||||||
|
|
@ -5,23 +5,32 @@ class SetMysqlToUnicodeMb4 < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
# shorten indexes regardless of the RDBMS provider - for consitency
|
# shorten indexes regardless of the RDBMS provider - for consitency
|
||||||
shorten_indexes
|
shorten_indexes
|
||||||
change_encoding('utf8mb4') if AppConfig.mysql?
|
change_encoding('utf8mb4', 'utf8mb4_bin') if AppConfig.mysql?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def self.down
|
||||||
change_encoding('utf8') if AppConfig.mysql?
|
change_encoding('utf8', 'utf8_bin') if AppConfig.mysql?
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_encoding(encoding)
|
def check_config(encoding, collation)
|
||||||
execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET #{encoding};"
|
connection_config = ActiveRecord::Base.connection_config
|
||||||
|
raise "Database encoding is not #{encoding}!" if connection_config[:encoding] != encoding
|
||||||
|
raise "Database collation is not #{collation}!" if connection_config[:collation] != collation
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_encoding(encoding, collation)
|
||||||
|
# Make sure the podmin changed the database.yml file
|
||||||
|
check_config(encoding, collation)
|
||||||
|
|
||||||
|
execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET #{encoding} COLLATE #{collation};"
|
||||||
|
|
||||||
tables.each do |table|
|
tables.each do |table|
|
||||||
execute "ALTER TABLE `#{table}` CHARACTER SET = #{encoding}"
|
execute "ALTER TABLE `#{table}` CHARACTER SET = #{encoding} COLLATE #{collation}"
|
||||||
end
|
end
|
||||||
|
|
||||||
character_columns.each do |table, columns|
|
character_columns.each do |table, columns|
|
||||||
columns.each do |column|
|
columns.each do |column|
|
||||||
execute "ALTER TABLE `#{table}` CHANGE `#{column.name}` `#{column.name}` #{column.sql_type} CHARACTER SET #{encoding} #{column.null ? 'NULL' : 'NOT NULL'} #{"DEFAULT '#{column.default}'" if column.has_default?};"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue