Add health check endpoint to verify that the locally running DB revision matches that of the database

Fixes #132
This commit is contained in:
Joseph Schorr 2015-06-15 15:52:08 -04:00
parent ae779cade2
commit 6e0dc1df08
2 changed files with 27 additions and 0 deletions

View file

@ -8,6 +8,7 @@ from urlparse import urlparse
from health.healthcheck import get_healthchecker
from data import model
from data.database import db
from data.model.oauth import DatabaseAuthorizationProvider
from app import app, billing as stripe, build_logs, avatar, signer, log_archive
from auth.auth import require_session_login, process_oauth
@ -227,6 +228,30 @@ def endtoend_health():
return response
@web.route('/health/dbrevision', methods=['GET'])
@route_show_if(features.BILLING)
@no_cache
def dbrevision_health():
# Find the revision from the database.
result = db.execute_sql('select * from alembic_version limit 1').fetchone()
db_revision = result[0]
# Find the local revision from the file system.
with open('ALEMBIC_HEAD', 'r') as f:
local_revision = f.readline().split(' ')[0]
data = {
'db_revision': db_revision,
'local_revision': local_revision,
}
status_code = 200 if db_revision == local_revision else 400
response = jsonify(dict(data=data, status_code=status_code))
response.status_code = status_code
return response
@web.route('/tos', methods=['GET'])
@no_cache
def tos():