Show More
The requested changes are too big and content was truncated. Show full diff
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -0,0 +1,27 b'' | |||||
|
1 | import logging | |||
|
2 | ||||
|
3 | from sqlalchemy import Column, MetaData, Integer, Unicode, ForeignKey, DateTime | |||
|
4 | ||||
|
5 | from rhodecode.lib.dbmigrate.versions import _reset_base | |||
|
6 | ||||
|
7 | log = logging.getLogger(__name__) | |||
|
8 | ||||
|
9 | ||||
|
10 | def upgrade(migrate_engine): | |||
|
11 | """ | |||
|
12 | Upgrade operations go here. | |||
|
13 | Don't create your own engine; bind migrate_engine to your metadata | |||
|
14 | """ | |||
|
15 | _reset_base(migrate_engine) | |||
|
16 | from rhodecode.lib.dbmigrate.schema import db_4_7_0_0 as db | |||
|
17 | ||||
|
18 | # add last_activity | |||
|
19 | user_table = db.User.__table__ | |||
|
20 | col1 = Column( | |||
|
21 | 'last_activity', DateTime(timezone=False), nullable=True, unique=None) | |||
|
22 | col1.create(table=user_table) | |||
|
23 | ||||
|
24 | ||||
|
25 | def downgrade(migrate_engine): | |||
|
26 | meta = MetaData() | |||
|
27 | meta.bind = migrate_engine |
@@ -0,0 +1,56 b'' | |||||
|
1 | import logging | |||
|
2 | import datetime | |||
|
3 | ||||
|
4 | from sqlalchemy import * | |||
|
5 | ||||
|
6 | from rhodecode.lib.utils2 import safe_str | |||
|
7 | from rhodecode.model import meta | |||
|
8 | from rhodecode.lib.dbmigrate.versions import _reset_base, notify | |||
|
9 | ||||
|
10 | log = logging.getLogger(__name__) | |||
|
11 | ||||
|
12 | ||||
|
13 | def time_to_datetime(tm): | |||
|
14 | if tm: | |||
|
15 | if isinstance(tm, basestring): | |||
|
16 | try: | |||
|
17 | tm = float(tm) | |||
|
18 | except ValueError: | |||
|
19 | return | |||
|
20 | return datetime.datetime.fromtimestamp(tm) | |||
|
21 | ||||
|
22 | ||||
|
23 | def upgrade(migrate_engine): | |||
|
24 | """ | |||
|
25 | Upgrade operations go here. | |||
|
26 | Don't create your own engine; bind migrate_engine to your metadata | |||
|
27 | """ | |||
|
28 | _reset_base(migrate_engine) | |||
|
29 | from rhodecode.lib.dbmigrate.schema import db_4_7_0_1 | |||
|
30 | ||||
|
31 | # fixups | |||
|
32 | fixups(db_4_7_0_1, meta.Session) | |||
|
33 | ||||
|
34 | ||||
|
35 | def downgrade(migrate_engine): | |||
|
36 | meta = MetaData() | |||
|
37 | meta.bind = migrate_engine | |||
|
38 | ||||
|
39 | ||||
|
40 | def _migrate_user(db, user): | |||
|
41 | last_activity = time_to_datetime(user.user_data.get('last_activity', 0)) | |||
|
42 | user.last_activity = last_activity | |||
|
43 | return user | |||
|
44 | ||||
|
45 | ||||
|
46 | def fixups(models, _SESSION): | |||
|
47 | # move the builtin token to external tokens | |||
|
48 | ||||
|
49 | query = models.User.query().all() | |||
|
50 | for user in query: | |||
|
51 | migrated_user = _migrate_user(models, user) | |||
|
52 | _SESSION.add(migrated_user) | |||
|
53 | log.info( | |||
|
54 | "Migrating last_activity of user '%s'.", safe_str(user.username)) | |||
|
55 | ||||
|
56 | _SESSION().commit() |
@@ -51,7 +51,7 b' PYRAMID_SETTINGS = {}' | |||||
51 | EXTENSIONS = {} |
|
51 | EXTENSIONS = {} | |
52 |
|
52 | |||
53 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) |
|
53 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) | |
54 |
__dbversion__ = |
|
54 | __dbversion__ = 70 # defines current db version for migrations | |
55 | __platform__ = platform.system() |
|
55 | __platform__ = platform.system() | |
56 | __license__ = 'AGPLv3, and Commercial License' |
|
56 | __license__ = 'AGPLv3, and Commercial License' | |
57 | __author__ = 'RhodeCode GmbH' |
|
57 | __author__ = 'RhodeCode GmbH' |
@@ -514,6 +514,8 b' class User(Base, BaseModel):' | |||||
514 | lastname = Column("lastname", String(255), nullable=True, unique=None, default=None) |
|
514 | lastname = Column("lastname", String(255), nullable=True, unique=None, default=None) | |
515 | _email = Column("email", String(255), nullable=True, unique=None, default=None) |
|
515 | _email = Column("email", String(255), nullable=True, unique=None, default=None) | |
516 | last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None) |
|
516 | last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None) | |
|
517 | last_activity = Column('last_activity', DateTime(timezone=False), nullable=True, unique=None, default=datetime.datetime.now) | |||
|
518 | ||||
517 | extern_type = Column("extern_type", String(255), nullable=True, unique=None, default=None) |
|
519 | extern_type = Column("extern_type", String(255), nullable=True, unique=None, default=None) | |
518 | extern_name = Column("extern_name", String(255), nullable=True, unique=None, default=None) |
|
520 | extern_name = Column("extern_name", String(255), nullable=True, unique=None, default=None) | |
519 | _api_key = Column("api_key", String(255), nullable=True, unique=None, default=None) |
|
521 | _api_key = Column("api_key", String(255), nullable=True, unique=None, default=None) |
General Comments 0
You need to be logged in to leave comments.
Login now