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() |
@@ -1,63 +1,63 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | """ |
|
22 | 22 | |
|
23 | 23 | RhodeCode, a web based repository management software |
|
24 | 24 | versioning implementation: http://www.python.org/dev/peps/pep-0386/ |
|
25 | 25 | """ |
|
26 | 26 | |
|
27 | 27 | import os |
|
28 | 28 | import sys |
|
29 | 29 | import platform |
|
30 | 30 | |
|
31 | 31 | VERSION = tuple(open(os.path.join( |
|
32 | 32 | os.path.dirname(__file__), 'VERSION')).read().split('.')) |
|
33 | 33 | |
|
34 | 34 | BACKENDS = { |
|
35 | 35 | 'hg': 'Mercurial repository', |
|
36 | 36 | 'git': 'Git repository', |
|
37 | 37 | 'svn': 'Subversion repository', |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | CELERY_ENABLED = False |
|
41 | 41 | CELERY_EAGER = False |
|
42 | 42 | |
|
43 | 43 | # link to config for pylons |
|
44 | 44 | CONFIG = {} |
|
45 | 45 | |
|
46 | 46 | # Populated with the settings dictionary from application init in |
|
47 | 47 | # rhodecode.conf.environment.load_pyramid_environment |
|
48 | 48 | PYRAMID_SETTINGS = {} |
|
49 | 49 | |
|
50 | 50 | # Linked module for extensions |
|
51 | 51 | EXTENSIONS = {} |
|
52 | 52 | |
|
53 | 53 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) |
|
54 |
__dbversion__ = 6 |
|
|
54 | __dbversion__ = 68 # defines current db version for migrations | |
|
55 | 55 | __platform__ = platform.system() |
|
56 | 56 | __license__ = 'AGPLv3, and Commercial License' |
|
57 | 57 | __author__ = 'RhodeCode GmbH' |
|
58 | 58 | __url__ = 'https://code.rhodecode.com' |
|
59 | 59 | |
|
60 | 60 | is_windows = __platform__ in ['Windows'] |
|
61 | 61 | is_unix = not is_windows |
|
62 | 62 | is_test = False |
|
63 | 63 | disable_error_handler = False |
General Comments 0
You need to be logged in to leave comments.
Login now