Created
September 6, 2015 23:44
-
-
Save justin808/17e0e22d5dd08877cd11 to your computer and use it in GitHub Desktop.
Check DB Version -- place this in config in your Rails app to ensure the team uses the same db version. Change line to match your expected DB.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method to check the DB version matches | |
# We ran into an issue where different versions of postgres caused inconsistent results. | |
def check_db_version | |
expected_db_version = "PostgreSQL 9.4" | |
adapter = ActiveRecord::Base.connection.adapter_name | |
sql = case adapter | |
when "MSSQL" | |
"SELECT @@VERSION" | |
when "MySQL", "Mysql2", "PostgreSQL" | |
"SELECT VERSION()" | |
when "OracleEnhanced" | |
"SELECT * FROM V$VERSION" | |
when "SQLite" | |
"SELECT SQLITE_VERSION()" | |
end | |
db_version = ActiveRecord::Base.connection.select_value(sql) | |
unless db_version.index(expected_db_version) | |
puts "X" * 80 | |
puts "Invalid DB version. Please use #{expected_db_version}, found #{db_version}" | |
puts "X" * 80 | |
end | |
end | |
check_db_version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment