From 26583b2cab650cc27af845fd2ef20cccae2aeceb Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Mon, 2 Sep 2013 09:47:55 -0700 Subject: [PATCH 1/2] check if db is up to date --- mediagoblin/app.py | 4 ++++ mediagoblin/db/util.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mediagoblin/app.py b/mediagoblin/app.py index e9177eff..e65e6d10 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -25,6 +25,7 @@ from werkzeug.exceptions import HTTPException from werkzeug.routing import RequestRedirect from mediagoblin import meddleware, __version__ +from mediagoblin.db.util import check_db_up_to_date from mediagoblin.tools import common, session, translate, template from mediagoblin.tools.response import render_http_exception from mediagoblin.tools.theme import register_themes @@ -91,6 +92,9 @@ class MediaGoblinApp(object): # Set up the database self.db = setup_database(app_config['run_migrations']) + # Quit app if need to run dbupdate + check_db_up_to_date() + # Register themes self.theme_registry, self.current_theme = register_themes(app_config) diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 8431361a..19e23d7f 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -14,9 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import sys + +from mediagoblin import mg_globals as mgg from mediagoblin.db.base import Session from mediagoblin.db.models import MediaEntry, Tag, MediaTag, Collection - +from mediagoblin.gmg_commands.dbupdate import gather_database_data ########################## # Random utility functions @@ -68,6 +71,18 @@ def check_collection_slug_used(creator_id, slug, ignore_c_id): return does_exist +def check_db_up_to_date(): + """Check if the database is up to date and quit if not""" + dbdatas = gather_database_data(mgg.global_config.get('plugins', {}).keys()) + + for dbdata in dbdatas: + migration_manager = dbdata.make_migration_manager(Session()) + if migration_manager.database_current_migration is None or \ + migration_manager.migrations_to_run(): + sys.exit("Your database is not up to date. Please run " + "'gmg dbupdate' before starting the webserver.") + + if __name__ == '__main__': from mediagoblin.db.open import setup_connection_and_db_from_config From 635dd6cc31d4d9afbe648f76af2f799eebf8f1f1 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Mon, 2 Sep 2013 11:55:41 -0700 Subject: [PATCH 2/2] don't set logging level to debug --- mediagoblin/gmg_commands/dbupdate.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 961752f6..77eaf01d 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -24,8 +24,6 @@ from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component _log = logging.getLogger(__name__) -logging.basicConfig() -_log.setLevel(logging.DEBUG) def dbupdate_parse_setup(subparser): pass