Show More
@@ -0,0 +1,55 | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | import logging | |||
|
4 | from collections import namedtuple | |||
|
5 | ||||
|
6 | from rhodecode.lib.dbmigrate.versions import _reset_base | |||
|
7 | from rhodecode.model import init_model_encryption, meta | |||
|
8 | ||||
|
9 | log = logging.getLogger(__name__) | |||
|
10 | ||||
|
11 | ||||
|
12 | def upgrade(migrate_engine): | |||
|
13 | """ | |||
|
14 | Upgrade operations go here. | |||
|
15 | Don't create your own engine; bind migrate_engine to your metadata | |||
|
16 | """ | |||
|
17 | _reset_base(migrate_engine) | |||
|
18 | from rhodecode.lib.dbmigrate.schema import db_3_7_0_0 | |||
|
19 | init_model_encryption(db_3_7_0_0) | |||
|
20 | fixups(db_3_7_0_0, meta.Session) | |||
|
21 | ||||
|
22 | ||||
|
23 | def downgrade(migrate_engine): | |||
|
24 | pass | |||
|
25 | ||||
|
26 | ||||
|
27 | AUTH_PLUGINS_SETTING = "auth_plugins" | |||
|
28 | ||||
|
29 | EXTERN_TYPE_RENAME_MAP = { | |||
|
30 | 'container': 'headers', | |||
|
31 | } | |||
|
32 | ||||
|
33 | # Only used for logging purposes. | |||
|
34 | RenameExternTypeOperation = namedtuple( | |||
|
35 | 'RenameExternTypeOperation', ['user', 'old', 'new']) | |||
|
36 | ||||
|
37 | ||||
|
38 | def fixups(models, Session): | |||
|
39 | operations = [] | |||
|
40 | ||||
|
41 | # Rename the extern_type attribute | |||
|
42 | query = models.User.query().filter( | |||
|
43 | models.User.extern_type.in_(EXTERN_TYPE_RENAME_MAP.keys())) | |||
|
44 | for user in query: | |||
|
45 | old = user.extern_type | |||
|
46 | new = EXTERN_TYPE_RENAME_MAP[old] | |||
|
47 | user.extern_type = new | |||
|
48 | Session.add(user) | |||
|
49 | operations.append(RenameExternTypeOperation(user, old, new)) | |||
|
50 | ||||
|
51 | log.info("Migration of users 'extern_type' attribute.") | |||
|
52 | for op in operations: | |||
|
53 | log.info("%s", op) | |||
|
54 | ||||
|
55 | Session().commit() |
General Comments 0
You need to be logged in to leave comments.
Login now