diff --git a/docs/en_US/release_notes_3_7.rst b/docs/en_US/release_notes_3_7.rst index 56cf48494..a070279b6 100644 --- a/docs/en_US/release_notes_3_7.rst +++ b/docs/en_US/release_notes_3_7.rst @@ -29,4 +29,5 @@ Bug fixes | `Bug #3797 `_ - Prevent attempts to bulk-drop schema objects. | `Bug #3798 `_ - Ensure the browser toolbar buttons work in languages other than English. | `Bug #3805 `_ - Allow horizontal sizing of the edit grid text pop-out. -| `Bug #3821 `_ - Ensure identifiers are properly displayed in the plan viewer. \ No newline at end of file +| `Bug #3821 `_ - Ensure identifiers are properly displayed in the plan viewer. +| `Bug #3830 `_ - Make the setup process more robust against aborted executions. \ No newline at end of file diff --git a/web/migrations/versions/fdc58d9bd449_.py b/web/migrations/versions/fdc58d9bd449_.py index d95983cdf..36c6819e3 100644 --- a/web/migrations/versions/fdc58d9bd449_.py +++ b/web/migrations/versions/fdc58d9bd449_.py @@ -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) diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index 36dfee36f..e119ac448 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -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) diff --git a/web/pgadmin/setup/__init__.py b/web/pgadmin/setup/__init__.py index 4a39ea924..a423a613d 100644 --- a/web/pgadmin/setup/__init__.py +++ b/web/pgadmin/setup/__init__.py @@ -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 diff --git a/web/pgadmin/setup/db_version.py b/web/pgadmin/setup/db_version.py index fa5068c7b..438d47966 100644 --- a/web/pgadmin/setup/db_version.py +++ b/web/pgadmin/setup/db_version.py @@ -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