Add collation and config check
This commit is contained in:
parent
c61a4a91a5
commit
0829e6f394
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.
|
||||
|
||||
## 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
|
||||
|
|
|
|||
Loading…
Reference in a new issue