Add a script to force migration of lazy tables and fix missing options in DAL init.

This commit is contained in:
2019-05-16 15:33:19 +01:00
parent 96534ccf30
commit 4455fa48c4
2 changed files with 46 additions and 2 deletions
+35
View File
@@ -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()