Skip to content

Instantly share code, notes, and snippets.

@justin808
Created September 6, 2015 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justin808/17e0e22d5dd08877cd11 to your computer and use it in GitHub Desktop.
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.
# 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