def get_current_version_from_comment():
"""
Return the current version of the database, from django_site comment.
Return None if the table django_site does not exist (schema not inited).
"""
with connection.cursor() as cursor:
try:
cursor.execute(
"SELECT obj_description('django_site'::regclass, 'pg_class');")
except ProgrammingError:
# table does not exist ?
return None
row = cursor.fetchone()
comment = row[0]
# no comment
if comment is None:
raise DBException('No comment found on django_site.')
# parse comment
if 'version ' not in comment:
raise DBException("No version found in django_site's comment.")
return comment.replace('version ', '').strip()
评论列表
文章目录