Allow pgAdmin to run with config database versions from the future. Fixes #2664

This commit is contained in:
Surinder Kumar 2017-08-29 15:03:02 +01:00 committed by Dave Page
parent ceb9438000
commit 7835da267b
2 changed files with 41 additions and 3 deletions

View File

@ -32,7 +32,9 @@ from werkzeug.utils import find_modules
from pgadmin.utils.preferences import Preferences
from pgadmin.model import db, Role, Server, ServerGroup, User, Keys
from pgadmin.model import db, Role, Server, ServerGroup, \
User, Keys, Version, SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
# If script is running under python3, it will not have the xrange function
# defined
@ -283,7 +285,25 @@ def create_app(app_name=None):
##########################################################################
# Upgrade the schema (if required)
##########################################################################
db_upgrade(app)
with app.app_context():
# Run migration for the first time i.e. create database
from config import SQLITE_PATH
if not os.path.exists(SQLITE_PATH):
db_upgrade(app)
else:
version = Version.query.filter_by(name='ConfigDB').first()
schema_version = version.value
# Run migration if current schema version is greater than the
# schema version stored in version table
if CURRENT_SCHEMA_VERSION >= schema_version:
db_upgrade(app)
# Update schema version to the latest
if CURRENT_SCHEMA_VERSION > schema_version:
version = Version.query.filter_by(name='ConfigDB').first()
version.value = CURRENT_SCHEMA_VERSION
db.session.commit()
Mail(app)

View File

@ -12,6 +12,7 @@ and settings database."""
import os
import sys
from pgadmin.model import db, Version, SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
if sys.version_info[0] >= 3:
import builtins
@ -50,4 +51,21 @@ if __name__ == '__main__':
print(u"======================================\n")
with app.app_context():
db_upgrade(app)
# Run migration for the first time i.e. create database
from config import SQLITE_PATH
if not os.path.exists(SQLITE_PATH):
db_upgrade(app)
else:
version = Version.query.filter_by(name='ConfigDB').first()
schema_version = version.value
# Run migration if current schema version is greater than the
# schema version stored in version table
if CURRENT_SCHEMA_VERSION >= schema_version:
db_upgrade(app)
# Update schema version to the latest
if CURRENT_SCHEMA_VERSION > schema_version:
version = Version.query.filter_by(name='ConfigDB').first()
version.value = CURRENT_SCHEMA_VERSION
db.session.commit()