##// END OF EJS Templates
user-journal: prepare new datastructure for v2 of user logs....
marcink -
r1624:e353283c default
parent child Browse files
Show More
@@ -0,0 +1,61 b''
1 import os
2 import logging
3 import datetime
4
5 from sqlalchemy import *
6 from sqlalchemy.exc import DatabaseError
7 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
8 from sqlalchemy.orm.session import Session
9 from sqlalchemy.ext.declarative import declarative_base
10
11 from rhodecode.lib.dbmigrate.migrate import *
12 from rhodecode.lib.dbmigrate.migrate.changeset import *
13 from rhodecode.lib.utils2 import str2bool
14
15 from rhodecode.model.meta import Base
16 from rhodecode.model import meta
17 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
18
19 log = logging.getLogger(__name__)
20
21
22 def get_by_key(cls, key):
23 return cls.query().filter(cls.ui_key == key).scalar()
24
25
26 def get_repos_location(cls):
27 return get_by_key(cls, '/').ui_value
28
29
30 def upgrade(migrate_engine):
31 """
32 Upgrade operations go here.
33 Don't create your own engine; bind migrate_engine to your metadata
34 """
35 _reset_base(migrate_engine)
36 from rhodecode.lib.dbmigrate.schema import db_4_7_0_1 as db
37
38 # add last_activity
39 user_log_table = db.UserLog.__table__
40
41 user_data = Column('user_data_json', db.JsonType(dialect_map=dict(mysql=UnicodeText(16384))))
42 user_data.create(table=user_log_table)
43
44 version = Column("version", String(255), nullable=True, default='v2')
45 version.create(table=user_log_table)
46
47 action_data = Column('action_data_json', db.JsonType(dialect_map=dict(mysql=UnicodeText(16384))))
48 action_data.create(table=user_log_table)
49
50 # issue fixups
51 fixups(db, meta.Session)
52
53
54 def downgrade(migrate_engine):
55 meta = MetaData()
56 meta.bind = migrate_engine
57
58
59 def fixups(models, _SESSION):
60 pass
61
@@ -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__ = 71 # defines current db version for migrations
54 __dbversion__ = 72 # 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'
@@ -1107,6 +1107,10 b' class UserLog(Base, BaseModel):'
1107 action = Column("action", Text().with_variant(Text(1200000), 'mysql'), nullable=True, unique=None, default=None)
1107 action = Column("action", Text().with_variant(Text(1200000), 'mysql'), nullable=True, unique=None, default=None)
1108 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
1108 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
1109
1109
1110 version = Column("version", String(255), nullable=True, default='v2')
1111 user_data = Column('user_data_json', MutationObj.as_mutable(JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
1112 action_data = Column('action_data_json', MutationObj.as_mutable(JsonType(dialect_map=dict(mysql=UnicodeText(16384)))))
1113
1110 def __unicode__(self):
1114 def __unicode__(self):
1111 return u"<%s('id:%s:%s')>" % (
1115 return u"<%s('id:%s:%s')>" % (
1112 self.__class__.__name__, self.repository_name, self.action)
1116 self.__class__.__name__, self.repository_name, self.action)
General Comments 0
You need to be logged in to leave comments. Login now