Make the setup process more robust against aborted executions. Fixes #3830

This commit is contained in:
Aditya Toshniwal 2018-12-21 10:30:49 +00:00 committed by Dave Page
parent f62d35bf3c
commit 943fc25f60
5 changed files with 17 additions and 8 deletions

View File

@ -29,4 +29,5 @@ Bug fixes
| `Bug #3797 <https://redmine.postgresql.org/issues/3797>`_ - Prevent attempts to bulk-drop schema objects.
| `Bug #3798 <https://redmine.postgresql.org/issues/3798>`_ - Ensure the browser toolbar buttons work in languages other than English.
| `Bug #3805 <https://redmine.postgresql.org/issues/3805>`_ - Allow horizontal sizing of the edit grid text pop-out.
| `Bug #3821 <https://redmine.postgresql.org/issues/3821>`_ - Ensure identifiers are properly displayed in the plan viewer.
| `Bug #3821 <https://redmine.postgresql.org/issues/3821>`_ - Ensure identifiers are properly displayed in the plan viewer.
| `Bug #3830 <https://redmine.postgresql.org/issues/3830>`_ - Make the setup process more robust against aborted executions.

View File

@ -40,6 +40,8 @@ def upgrade():
if get_version() != -1:
return
email, password = user_info()
op.create_table('version',
sa.Column('name', sa.String(length=32), nullable=False),
sa.Column('value', sa.Integer(), nullable=False),
@ -109,7 +111,6 @@ INSERT INTO "servergroup"
VALUES(1, 1, 'Servers')
""")
email, password = user_info()
current_salt = getattr(
config, 'SECURITY_PASSWORD_SALT', base64.urlsafe_b64encode(
os.urandom(32)

View File

@ -33,6 +33,7 @@ from pgadmin.utils.preferences import Preferences
from pgadmin.utils.session import create_session_interface, pga_unauthorised
from pgadmin.utils.versioned_template_loader import VersionedTemplateLoader
from datetime import timedelta
from pgadmin.setup import get_version, set_version
# If script is running under python3, it will not have the xrange function
# defined
@ -304,11 +305,13 @@ def create_app(app_name=None):
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):
# If version not available, user must have aborted. Tables are not
# created and so its an empty db
if not os.path.exists(SQLITE_PATH) or get_version() == -1:
db_upgrade(app)
else:
version = Version.query.filter_by(name='ConfigDB').first()
schema_version = version.value
schema_version = get_version()
# Run migration if current schema version is greater than the
# schema version stored in version table
@ -317,8 +320,7 @@ def create_app(app_name=None):
# 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
set_version(CURRENT_SCHEMA_VERSION)
db.session.commit()
Mail(app)

View File

@ -8,6 +8,6 @@
##########################################################################
from .user_info import user_info
from .db_version import get_version
from .db_version import get_version, set_version
from .db_upgrade import db_upgrade
from .data_directory import create_app_data_directory

View File

@ -17,3 +17,8 @@ def get_version():
return -1
return version.value
def set_version(new_version):
version = Version.query.filter_by(name='ConfigDB').first()
version.value = new_version