Commit 0829e6f3 authored by Dumitru Ursu's avatar Dumitru Ursu

Add collation and config check

parent c61a4a91
......@@ -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.
## 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.
Also, do not forget to remove `collation: utf8_bin`. It will choose a compatible one automatically.
For MySQL databases, replace `charset: utf8` with `encoding: utf8mb4m` and change `collation` from `utf8_bin` to `utf8mb4_bin` in the file `config/database.yml`.
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!
## Experimental chat feature
......
......@@ -6,6 +6,7 @@ mysql: &mysql
password: ""
# socket: /tmp/mysql.sock
encoding: utf8mb4
collation: utf8mb4_bin
postgres: &postgres
adapter: postgresql
......
......@@ -5,23 +5,32 @@ class SetMysqlToUnicodeMb4 < ActiveRecord::Migration
def self.up
# shorten indexes regardless of the RDBMS provider - for consitency
shorten_indexes
change_encoding('utf8mb4') if AppConfig.mysql?
change_encoding('utf8mb4', 'utf8mb4_bin') if AppConfig.mysql?
end
def self.down
change_encoding('utf8') if AppConfig.mysql?
change_encoding('utf8', 'utf8_bin') if AppConfig.mysql?
end
def change_encoding(encoding)
execute "ALTER DATABASE `#{ActiveRecord::Base.connection.current_database}` CHARACTER SET #{encoding};"
def check_config(encoding, collation)
connection_config = ActiveRecord::Base.connection_config
fail "Database encoding is not #{encoding}!" if connection_config[:encoding] != encoding
fail "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|
execute "ALTER TABLE `#{table}` CHARACTER SET = #{encoding}"
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} #{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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment