Show More
@@ -0,0 +1,65 b'' | |||
|
1 | import logging | |
|
2 | ||
|
3 | from sqlalchemy import * | |
|
4 | from sqlalchemy.engine import reflection | |
|
5 | ||
|
6 | from alembic.migration import MigrationContext | |
|
7 | from alembic.operations import Operations | |
|
8 | ||
|
9 | from rhodecode.model import meta | |
|
10 | from rhodecode.lib.dbmigrate.versions import _reset_base, notify | |
|
11 | ||
|
12 | log = logging.getLogger(__name__) | |
|
13 | ||
|
14 | ||
|
15 | def get_by_key(cls, key): | |
|
16 | return cls.query().filter(cls.ui_key == key).scalar() | |
|
17 | ||
|
18 | ||
|
19 | def upgrade(migrate_engine): | |
|
20 | """ | |
|
21 | Upgrade operations go here. | |
|
22 | Don't create your own engine; bind migrate_engine to your metadata | |
|
23 | """ | |
|
24 | _reset_base(migrate_engine) | |
|
25 | from rhodecode.lib.dbmigrate.schema import db_4_7_0_0 | |
|
26 | ||
|
27 | # make sure we re-create api-keys indexes | |
|
28 | ||
|
29 | context = MigrationContext.configure(migrate_engine.connect()) | |
|
30 | op = Operations(context) | |
|
31 | ||
|
32 | existing_indexes = _get_indexes_list( | |
|
33 | migrate_engine, db_4_7_0_0.UserApiKeys.__tablename__) | |
|
34 | ||
|
35 | names = [idx['name'] for idx in existing_indexes] | |
|
36 | ||
|
37 | with op.batch_alter_table(db_4_7_0_0.UserApiKeys.__tablename__) as batch_op: | |
|
38 | if 'uak_api_key_idx' not in names: | |
|
39 | batch_op.create_index( | |
|
40 | 'uak_api_key_idx', ['api_key']) | |
|
41 | if 'uak_api_key_expires_idx' not in names: | |
|
42 | batch_op.create_index( | |
|
43 | 'uak_api_key_expires_idx', ['api_key', 'expires']) | |
|
44 | ||
|
45 | # issue fixups | |
|
46 | fixups(db_4_7_0_0, meta.Session) | |
|
47 | ||
|
48 | ||
|
49 | def downgrade(migrate_engine): | |
|
50 | meta = MetaData() | |
|
51 | meta.bind = migrate_engine | |
|
52 | ||
|
53 | ||
|
54 | def fixups(models, _SESSION): | |
|
55 | pass | |
|
56 | ||
|
57 | ||
|
58 | def _get_unique_constraint_list(migrate_engine, table_name): | |
|
59 | inspector = reflection.Inspector.from_engine(migrate_engine) | |
|
60 | return inspector.get_unique_constraints(table_name) | |
|
61 | ||
|
62 | ||
|
63 | def _get_indexes_list(migrate_engine, table_name): | |
|
64 | inspector = reflection.Inspector.from_engine(migrate_engine) | |
|
65 | return inspector.get_indexes(table_name) |
@@ -0,0 +1,44 b'' | |||
|
1 | import logging | |
|
2 | ||
|
3 | from sqlalchemy import * | |
|
4 | from rhodecode.model import meta | |
|
5 | from rhodecode.lib.dbmigrate.versions import _reset_base, notify | |
|
6 | ||
|
7 | log = logging.getLogger(__name__) | |
|
8 | ||
|
9 | ||
|
10 | def get_by_key(cls, key): | |
|
11 | return cls.query().filter(cls.ui_key == key).scalar() | |
|
12 | ||
|
13 | ||
|
14 | def upgrade(migrate_engine): | |
|
15 | """ | |
|
16 | Upgrade operations go here. | |
|
17 | Don't create your own engine; bind migrate_engine to your metadata | |
|
18 | """ | |
|
19 | _reset_base(migrate_engine) | |
|
20 | from rhodecode.lib.dbmigrate.schema import db_4_7_0_0 | |
|
21 | ||
|
22 | auth_token_table = db_4_7_0_0.UserApiKeys.__table__ | |
|
23 | ||
|
24 | repo_id = Column( | |
|
25 | 'repo_id', Integer(), ForeignKey('repositories.repo_id'), | |
|
26 | nullable=True, unique=None, default=None) | |
|
27 | repo_id.create(table=auth_token_table) | |
|
28 | ||
|
29 | repo_group_id = Column( | |
|
30 | 'repo_group_id', Integer(), ForeignKey('groups.group_id'), | |
|
31 | nullable=True, unique=None, default=None) | |
|
32 | repo_group_id.create(table=auth_token_table) | |
|
33 | ||
|
34 | # issue fixups | |
|
35 | fixups(db_4_7_0_0, meta.Session) | |
|
36 | ||
|
37 | ||
|
38 | def downgrade(migrate_engine): | |
|
39 | meta = MetaData() | |
|
40 | meta.bind = migrate_engine | |
|
41 | ||
|
42 | ||
|
43 | def fixups(models, _SESSION): | |
|
44 | pass |
@@ -51,7 +51,7 b' PYRAMID_SETTINGS = {}' | |||
|
51 | 51 | EXTENSIONS = {} |
|
52 | 52 | |
|
53 | 53 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) |
|
54 |
__dbversion__ = 6 |
|
|
54 | __dbversion__ = 67 # defines current db version for migrations | |
|
55 | 55 | __platform__ = platform.system() |
|
56 | 56 | __license__ = 'AGPLv3, and Commercial License' |
|
57 | 57 | __author__ = 'RhodeCode GmbH' |
@@ -955,6 +955,17 b' class UserApiKeys(Base, BaseModel):' | |||
|
955 | 955 | role = Column('role', String(255), nullable=True) |
|
956 | 956 | created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) |
|
957 | 957 | |
|
958 | # scope columns | |
|
959 | repo_id = Column( | |
|
960 | 'repo_id', Integer(), ForeignKey('repositories.repo_id'), | |
|
961 | nullable=True, unique=None, default=None) | |
|
962 | repo = relationship('Repository', lazy='joined') | |
|
963 | ||
|
964 | repo_group_id = Column( | |
|
965 | 'repo_group_id', Integer(), ForeignKey('groups.group_id'), | |
|
966 | nullable=True, unique=None, default=None) | |
|
967 | repo_group = relationship('RepoGroup', lazy='joined') | |
|
968 | ||
|
958 | 969 | user = relationship('User', lazy='joined') |
|
959 | 970 | |
|
960 | 971 | @classmethod |
General Comments 0
You need to be logged in to leave comments.
Login now