mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
Allow pgAdmin to run with config database versions from the future. Fixes #2664
This commit is contained in:
parent
ceb9438000
commit
7835da267b
@ -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)
|
||||
|
||||
|
20
web/setup.py
20
web/setup.py
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user