Add a script to force migration of lazy tables and fix missing options in DAL init.
This commit is contained in:
1 parent
96534ccf30
commit
4455fa48c4
2 files changed
+46
-2
No files matched your search
+11
-2
@@ -251,12 +251,12 @@ def run(
|
|||||||
orig_init = DAL.__init__
|
orig_init = DAL.__init__
|
||||||
|
|
||||||
def custom_init(*args, **kwargs):
|
def custom_init(*args, **kwargs):
|
||||||
|
kwargs['migrate_enabled'] = True
|
||||||
kwargs['migrate'] = True
|
kwargs['migrate'] = True
|
||||||
logger.info('Forcing migrate=True')
|
logger.info('Forcing migrate_enabled=True')
|
||||||
orig_init(*args, **kwargs)
|
orig_init(*args, **kwargs)
|
||||||
|
|
||||||
DAL.__init__ = custom_init
|
DAL.__init__ = custom_init
|
||||||
logger.debug('Custom init should not have been called already')
|
|
||||||
|
|
||||||
if c:
|
if c:
|
||||||
import_models = True
|
import_models = True
|
||||||
@@ -310,6 +310,15 @@ def run(
|
|||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
if import_models:
|
if import_models:
|
||||||
BaseAdapter.close_all_instances('rollback')
|
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:
|
else:
|
||||||
if not plain:
|
if not plain:
|
||||||
if bpython:
|
if bpython:
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
To use, e.g. python .\web2py.py -S APPNAME --force_migrate
|
||||||
|
'''
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger("web2py")
|
||||||
|
|
||||||
|
|
||||||
|
def get_databases(request):
|
||||||
|
dbs = {}
|
||||||
|
global_env = globals()
|
||||||
|
for (key, value) in global_env.items():
|
||||||
|
try:
|
||||||
|
cond = isinstance(value, GQLDB)
|
||||||
|
except:
|
||||||
|
cond = isinstance(value, SQLDB)
|
||||||
|
if cond:
|
||||||
|
dbs[key] = value
|
||||||
|
return dbs
|
||||||
|
|
||||||
|
|
||||||
|
logger.debug('Getting all databases')
|
||||||
|
databases = get_databases(None)
|
||||||
|
logger.debug('databases = %s', databases)
|
||||||
|
for db_name in databases:
|
||||||
|
logger.debug('Migrating %s', db_name)
|
||||||
|
db = databases[db_name]
|
||||||
|
tables = db.tables
|
||||||
|
for table_name in tables:
|
||||||
|
# Force migration of lazy tables
|
||||||
|
logger.debug("Ensuring migration of table '%s'", table_name)
|
||||||
|
db(db[table_name]).isempty()
|
||||||
|
db.commit()
|
||||||
Reference in new issue
Block a user