From b4c2ee830429a8c1e2f14d3612e4671f6b40233b Mon Sep 17 00:00:00 2001 From: Dinis Date: Thu, 25 Jul 2019 17:15:19 +0100 Subject: [PATCH] Allow easily switching fake_migrate on to allow easier fixes of the database migrations --- gluon/console.py | 6 ++++++ gluon/shell.py | 4 +++- gluon/widget.py | 3 ++- scripts/migrator.py | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gluon/console.py b/gluon/console.py index 624941a7..10cf5a23 100644 --- a/gluon/console.py +++ b/gluon/console.py @@ -266,6 +266,12 @@ web2py will attempt to run a GUI to ask for it when starting the web server '(default is %(default)s), see -S above. NOTE: when the APP_ENV ' 'argument of -S include a controller c automatic import of ' 'models is always enabled') + g.add_argument('--fake_migrate', + default=False, + action='store_true', + help= + 'force DAL to fake migrate all tables; ' + 'monkeypatch in the DAL class to force _fake_migrate=True') g.add_argument('--force_migrate', '--force-migrate', default=False, action='store_true', help= diff --git a/gluon/shell.py b/gluon/shell.py index f8de2abd..f249c341 100644 --- a/gluon/shell.py +++ b/gluon/shell.py @@ -217,7 +217,8 @@ def run( python_code=None, cron_job=False, scheduler_job=False, - force_migrate=False): + force_migrate=False, + fake_migrate=False): """ Start interactive shell or run Python script (startfile) in web2py controller environment. appname is formatted like: @@ -255,6 +256,7 @@ def run( def custom_init(*args, **kwargs): kwargs['migrate_enabled'] = True kwargs['migrate'] = True + kwargs['fake_migrate'] = fake_migrate logger.info('Forcing migrate_enabled=True') orig_init(*args, **kwargs) diff --git a/gluon/widget.py b/gluon/widget.py index b41974ff..98d6791d 100644 --- a/gluon/widget.py +++ b/gluon/widget.py @@ -741,7 +741,8 @@ def start(): sys.argv = [options.run or ''] + options.args run(options.shell, plain=options.plain, bpython=options.bpython, import_models=options.import_models, startfile=options.run, - cron_job=options.cron_job, force_migrate=options.force_migrate) + cron_job=options.cron_job, force_migrate=options.force_migrate, + fake_migrate=options.fake_migrate) return # set size of cron thread pools diff --git a/scripts/migrator.py b/scripts/migrator.py index d94c5fa6..6f9c9a65 100644 --- a/scripts/migrator.py +++ b/scripts/migrator.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- ''' To use, e.g. python .\web2py.py -S APPNAME --force_migrate +To use, e.g. python .\web2py.py -S APPNAME --force_migrate --fake_migrate ''' import logging @@ -31,5 +32,6 @@ for db_name in databases: for table_name in tables: # Force migration of lazy tables logger.debug("Ensuring migration of table '%s'", table_name) - db(db[table_name]).isempty() + table = db[table_name] + db(table).isempty() db.commit()