##// END OF EJS Templates
auth-tokens: migrate builtin token to the external ones
marcink -
r1476:93b1bbd9 default
parent child Browse files
Show More
@@ -0,0 +1,54 b''
1 import logging
2
3 from sqlalchemy import *
4
5 from rhodecode.lib.utils2 import safe_str
6 from rhodecode.model import meta
7 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
8
9 log = logging.getLogger(__name__)
10
11
12 def get_by_key(cls, key):
13 return cls.query().filter(cls.ui_key == key).scalar()
14
15
16 def upgrade(migrate_engine):
17 """
18 Upgrade operations go here.
19 Don't create your own engine; bind migrate_engine to your metadata
20 """
21 _reset_base(migrate_engine)
22 from rhodecode.lib.dbmigrate.schema import db_4_7_0_0
23
24 # fixups
25 fixups(db_4_7_0_0, meta.Session)
26
27
28 def downgrade(migrate_engine):
29 meta = MetaData()
30 meta.bind = migrate_engine
31
32
33 def _migrate_token(db, user):
34 new_auth_token = db.UserApiKeys()
35 new_auth_token.api_key = user.api_key
36 new_auth_token.user_id = user.user_id
37 new_auth_token.description = 'Migrated Builtin Token'
38 new_auth_token.role = db.UserApiKeys.ROLE_ALL
39 new_auth_token.expires = -1
40 return new_auth_token
41
42
43 def fixups(models, _SESSION):
44 # move the builtin token to external tokens
45
46 query = models.User.query().all()
47 for user in query:
48 builtin_token = user.api_key
49 if builtin_token:
50 log.info("Migrating builtin token of user '%s'.", safe_str(user.username))
51 migrated_token = _migrate_token(models, user)
52 _SESSION.add(migrated_token)
53
54 _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__ = 67 # defines current db version for migrations
54 __dbversion__ = 68 # 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'
General Comments 0
You need to be logged in to leave comments. Login now