First attempt to force migration of the tables even with migrate option set to false.
This commit is contained in:
+15
-1
@@ -214,7 +214,8 @@ def run(
|
|||||||
bpython=False,
|
bpython=False,
|
||||||
python_code=None,
|
python_code=None,
|
||||||
cronjob=False,
|
cronjob=False,
|
||||||
scheduler_job=False):
|
scheduler_job=False,
|
||||||
|
force_migrate=False):
|
||||||
"""
|
"""
|
||||||
Start interactive shell or run Python script (startfile) in web2py
|
Start interactive shell or run Python script (startfile) in web2py
|
||||||
controller environment. appname is formatted like:
|
controller environment. appname is formatted like:
|
||||||
@@ -244,6 +245,19 @@ def run(
|
|||||||
os.mkdir(adir)
|
os.mkdir(adir)
|
||||||
fileutils.create_app(adir)
|
fileutils.create_app(adir)
|
||||||
|
|
||||||
|
if force_migrate:
|
||||||
|
import_models = True
|
||||||
|
from gluon.dal import DAL
|
||||||
|
orig_init = DAL.__init__
|
||||||
|
|
||||||
|
def custom_init(*args, **kwargs):
|
||||||
|
kwargs['migrate'] = True
|
||||||
|
logger.info('Forcing migrate=True')
|
||||||
|
orig_init(*args, **kwargs)
|
||||||
|
|
||||||
|
DAL.__init__ = custom_init
|
||||||
|
logger.debug('Custom init should not have been called already')
|
||||||
|
|
||||||
if c:
|
if c:
|
||||||
import_models = True
|
import_models = True
|
||||||
extra_request = {}
|
extra_request = {}
|
||||||
|
|||||||
+8
-1
@@ -839,6 +839,13 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
'collect coverage data when used with --run_system_tests; ' \
|
'collect coverage data when used with --run_system_tests; ' \
|
||||||
'require Python 2.7+ and the coverage module installed')
|
'require Python 2.7+ and the coverage module installed')
|
||||||
|
|
||||||
|
parser.add_option('--force_migrate',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help= \
|
||||||
|
'force DAL to migrate all tables that should be migrated when enabled; ' \
|
||||||
|
'monkeypatch in the DAL class to force _migrate_enabled=True')
|
||||||
|
|
||||||
if '-A' in sys.argv:
|
if '-A' in sys.argv:
|
||||||
k = sys.argv.index('-A')
|
k = sys.argv.index('-A')
|
||||||
elif '--args' in sys.argv:
|
elif '--args' in sys.argv:
|
||||||
@@ -1037,7 +1044,7 @@ def start():
|
|||||||
sys.argv = [options.run] + options.args
|
sys.argv = [options.run] + options.args
|
||||||
run(options.shell, plain=options.plain, bpython=options.bpython,
|
run(options.shell, plain=options.plain, bpython=options.bpython,
|
||||||
import_models=options.import_models, startfile=options.run,
|
import_models=options.import_models, startfile=options.run,
|
||||||
cronjob=options.cronjob)
|
cronjob=options.cronjob, force_migrate=options.force_migrate)
|
||||||
return
|
return
|
||||||
|
|
||||||
if options.extcron:
|
if options.extcron:
|
||||||
|
|||||||
Reference in New Issue
Block a user