From d63b54610b8b70aae781196a5acee24e4f39c307 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 24 Jun 2016 12:50:52 +0100 Subject: [PATCH] Move the config database schema version out of the configuration file and into the model class. Turns out using the config file isn't a good idea if users copy config.py to config_local.py, as it prevents upgrades to the database. This has the added side-effect of simplifying future changes, as you only need to edit 2 files to modify the config DB now, not 3. --- web/config.py | 4 ---- web/pgAdmin4.py | 5 +++++ web/pgadmin/model/__init__.py | 18 +++++++++++++++++- web/setup.py | 5 +++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/web/config.py b/web/config.py index 78f2b63c7..f382648e9 100644 --- a/web/config.py +++ b/web/config.py @@ -154,10 +154,6 @@ MAX_SESSION_IDLE_TIME = 60 # User account and settings storage ########################################################################## -# The schema version number for the configuration database -# DO NOT CHANGE UNLESS YOU ARE A PGADMIN DEVELOPER!! -SETTINGS_SCHEMA_VERSION = 13 - # The default path to the SQLite database used to store user accounts and # settings. This default places the file in the same directory as this # config file, but generates an absolute path for use througout the app. diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 89c4e10b1..b679cd62e 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -23,6 +23,11 @@ if sys.path[0] != root: import config from pgadmin import create_app +# Get the config database schema version. We store this in pgadmin.model +# as it turns out that putting it in the config files isn't a great idea +from pgadmin.model import SCHEMA_VERSION +config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION + ########################################################################## # Sanity checks ########################################################################## diff --git a/web/pgadmin/model/__init__.py b/web/pgadmin/model/__init__.py index d477a2d41..68c16c102 100644 --- a/web/pgadmin/model/__init__.py +++ b/web/pgadmin/model/__init__.py @@ -12,7 +12,7 @@ If any of the models are updated, you (yes, you, the developer) MUST do two things: -1) Increment SETTINGS_SCHEMA_VERSION in config.py +1) Increment SCHEMA_VERSION below 2) Modify setup.py to ensure that the appropriate changes are made to the config database to upgrade it to the new version. @@ -21,6 +21,22 @@ things: from flask.ext.security import UserMixin, RoleMixin from flask.ext.sqlalchemy import SQLAlchemy +########################################################################## +# +# The schema version is used to track when upgrades are needed to the +# configuration database. Increment this whenever changes are made to the +# model or data, AND ensure the upgrade code is added to setup.py +# +########################################################################## + +SCHEMA_VERSION = 13 + +########################################################################## +# +# And now we return to our regularly scheduled programming: +# +########################################################################## + db = SQLAlchemy() # Define models diff --git a/web/setup.py b/web/setup.py index a90fd1236..be37e8410 100644 --- a/web/setup.py +++ b/web/setup.py @@ -26,6 +26,11 @@ from pgadmin.model import db, Role, User, Server, \ # Configuration settings import config +# Get the config database schema version. We store this in pgadmin.model +# as it turns out that putting it in the config files isn't a great idea +from pgadmin.model import SCHEMA_VERSION +config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION + # If script is running under python2 then change the behaviour of functions if hasattr(__builtins__, 'raw_input'): input = raw_input