Merge branch 'migrator-pr' into dev-ah
This commit is contained in:
+24
-1
@@ -220,7 +220,8 @@ def run(
|
||||
bpython=False,
|
||||
python_code=None,
|
||||
cron_job=False,
|
||||
scheduler_job=False):
|
||||
scheduler_job=False,
|
||||
force_migrate=False):
|
||||
"""
|
||||
Start interactive shell or run Python script (startfile) in web2py
|
||||
controller environment. appname is formatted like:
|
||||
@@ -250,6 +251,19 @@ def run(
|
||||
os.mkdir(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_enabled'] = True
|
||||
kwargs['migrate'] = True
|
||||
logger.info('Forcing migrate_enabled=True')
|
||||
orig_init(*args, **kwargs)
|
||||
|
||||
DAL.__init__ = custom_init
|
||||
|
||||
if c:
|
||||
import_models = True
|
||||
extra_request = {}
|
||||
@@ -303,6 +317,15 @@ def run(
|
||||
print(traceback.format_exc())
|
||||
if import_models:
|
||||
BaseAdapter.close_all_instances('rollback')
|
||||
elif force_migrate:
|
||||
try:
|
||||
execfile("scripts/migrator.py", _env)
|
||||
if import_models:
|
||||
BaseAdapter.close_all_instances('commit')
|
||||
except:
|
||||
print(traceback.format_exc())
|
||||
if import_models:
|
||||
BaseAdapter.close_all_instances('rollback')
|
||||
else:
|
||||
if not plain:
|
||||
if bpython:
|
||||
|
||||
Reference in New Issue
Block a user