##// END OF EJS Templates
validators/schemas: python3 fixes str vs unicode and few test breaking fixes
validators/schemas: python3 fixes str vs unicode and few test breaking fixes

File last commit:

r4908:04e2d7da default
r5066:ccd88b7c default
Show More
070_version_4_7_0.py
56 lines | 1.3 KiB | text/x-python | PythonLexer
users: migrate last_activity column so it's part of user table....
r1545 import logging
import datetime
from sqlalchemy import *
from rhodecode.lib.utils2 import safe_str
from rhodecode.model import meta
from rhodecode.lib.dbmigrate.versions import _reset_base, notify
log = logging.getLogger(__name__)
def time_to_datetime(tm):
if tm:
py3: remove use of pyramid.compat
r4908 if isinstance(tm, str):
users: migrate last_activity column so it's part of user table....
r1545 try:
tm = float(tm)
except ValueError:
return
return datetime.datetime.fromtimestamp(tm)
def upgrade(migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata
"""
_reset_base(migrate_engine)
from rhodecode.lib.dbmigrate.schema import db_4_7_0_1
# fixups
fixups(db_4_7_0_1, meta.Session)
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
def _migrate_user(db, user):
last_activity = time_to_datetime(user.user_data.get('last_activity', 0))
user.last_activity = last_activity
return user
def fixups(models, _SESSION):
# move the builtin token to external tokens
query = models.User.query().all()
for user in query:
migrated_user = _migrate_user(models, user)
_SESSION.add(migrated_user)
log.info(
"Migrating last_activity of user '%s'.", safe_str(user.username))
_SESSION().commit()