Fixed issue#237 - added database version check at app boot sequence - thanks to @zotto and @qpwr

This commit is contained in:
Martin Edenhofer 2016-10-20 23:18:26 +02:00
parent a6893a34de
commit d7115a6be5
3 changed files with 61 additions and 11 deletions

View file

@ -4,14 +4,3 @@
Rails.application.config.db_case_sensitive = false
Rails.application.config.db_like = 'LIKE'
Rails.application.config.db_4bytes_utf8 = true
# postgresql
if ActiveRecord::Base.connection_config[:adapter] == 'postgresql'
Rails.application.config.db_case_sensitive = true
Rails.application.config.db_like = 'ILIKE'
end
# mysql
if ActiveRecord::Base.connection_config[:adapter] == 'mysql2'
Rails.application.config.db_4bytes_utf8 = false
end

View file

@ -0,0 +1,39 @@
# mysql
if ActiveRecord::Base.connection_config[:adapter] == 'mysql2'
Rails.application.config.db_4bytes_utf8 = false
# mysql version check
# mysql example: "5.7.3"
# mariadb example: "10.1.17-MariaDB"
server_version = ActiveRecord::Base.connection.select_rows('SHOW VARIABLES LIKE \'version\'')[0][1]
raise 'Unable to retrive database version' if !server_version
(server_version, server_vendor) = server_version.split('-')
if !server_vendor
server_vendor = 'MySQL'
end
(major, minor) = server_version.split('.')
if server_vendor == 'MySQL'
if major.to_i < 5 || (major.to_i == 5 && minor.to_i < 6)
# rubocop:disable Rails/Output
# rubocop:disable Rails/Exit
p '+++++++++++++++++++++++++++++++++++++++++++++++++++++'
p '+ I\'m sorry, MySQL 5.6+ is required +'
p '+++++++++++++++++++++++++++++++++++++++++++++++++++++'
exit 1
# rubocop:enable Rails/Exit
# rubocop:enable Rails/Output
end
elsif major.to_i < 10
# rubocop:disable Rails/Output
# rubocop:disable Rails/Exit
p '+++++++++++++++++++++++++++++++++++++++++++++++++++++'
p '+ I\'m sorry, MariaDB 10.0+ is required +'
p '+++++++++++++++++++++++++++++++++++++++++++++++++++++'
exit 1
# rubocop:enable Rails/Exit
# rubocop:enable Rails/Output
end
end

View file

@ -0,0 +1,22 @@
# postgresql
if ActiveRecord::Base.connection_config[:adapter] == 'postgresql'
Rails.application.config.db_case_sensitive = true
Rails.application.config.db_like = 'ILIKE'
# postgresql version check
# example output: "9.5.0"
server_version = ActiveRecord::Base.connection.select_rows('SHOW server_version;')[0][0]
(major, minor) = server_version.split('.')
if major.to_i < 9 || (major.to_i == 9 && minor.to_i < 1)
# rubocop:disable Rails/Output
# rubocop:disable Rails/Exit
p '+++++++++++++++++++++++++++++++++++++++++++++++++++++'
p '+ I\'m sorry, PostgreSQL 9.1+ is required +'
p '+++++++++++++++++++++++++++++++++++++++++++++++++++++'
exit 1
# rubocop:enable Rails/Exit
# rubocop:enable Rails/Output
end
end