##// END OF EJS Templates
routing: improve bad character detection on repo names
routing: improve bad character detection on repo names

File last commit:

r3425:d577b778 default
r4843:05c94e8b default
Show More
070_version_4_7_0.py
57 lines | 1.4 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 *
dan
py3: remove usage of basestring
r3425 from pyramid import compat
users: migrate last_activity column so it's part of user table....
r1545
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:
dan
py3: remove usage of basestring
r3425 if isinstance(tm, compat.string_types):
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()