##// END OF EJS Templates
db: added index to cache_args column for feaster lookup on cache invalidation
super-admin -
r4830:b6a62e17 default
parent child Browse files
Show More
@@ -0,0 +1,54 b''
1 # -*- coding: utf-8 -*-
2
3 import logging
4 from sqlalchemy import *
5 from sqlalchemy.engine import reflection
6
7 from alembic.migration import MigrationContext
8 from alembic.operations import Operations
9
10 from rhodecode.lib.dbmigrate.versions import _reset_base
11 from rhodecode.model import meta, init_model_encryption
12
13
14 log = logging.getLogger(__name__)
15
16
17 def _get_indexes_list(migrate_engine, table_name):
18 inspector = reflection.Inspector.from_engine(migrate_engine)
19 return inspector.get_indexes(table_name)
20
21
22 def upgrade(migrate_engine):
23 """
24 Upgrade operations go here.
25 Don't create your own engine; bind migrate_engine to your metadata
26 """
27 _reset_base(migrate_engine)
28 from rhodecode.lib.dbmigrate.schema import db_4_20_0_0
29
30 init_model_encryption(db_4_20_0_0)
31
32 # make sure we re-create api-keys indexes
33
34 context = MigrationContext.configure(migrate_engine.connect())
35 op = Operations(context)
36
37 existing_indexes = _get_indexes_list(
38 migrate_engine, db_4_20_0_0.CacheKey.__tablename__)
39
40 names = [idx['name'] for idx in existing_indexes]
41
42 with op.batch_alter_table(db_4_20_0_0.CacheKey.__tablename__) as batch_op:
43 if 'cache_args_idx' not in names:
44 batch_op.create_index(
45 'cache_args_idx', ['cache_args'])
46
47
48 def downgrade(migrate_engine):
49 meta = MetaData()
50 meta.bind = migrate_engine
51
52
53 def fixups(models, _SESSION):
54 pass
@@ -48,7 +48,7 b' PYRAMID_SETTINGS = {}'
48 48 EXTENSIONS = {}
49 49
50 50 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
51 __dbversion__ = 113 # defines current db version for migrations
51 __dbversion__ = 114 # defines current db version for migrations
52 52 __platform__ = platform.system()
53 53 __license__ = 'AGPLv3, and Commercial License'
54 54 __author__ = 'RhodeCode GmbH'
@@ -3654,6 +3654,7 b' class CacheKey(Base, BaseModel):'
3654 3654 __table_args__ = (
3655 3655 UniqueConstraint('cache_key'),
3656 3656 Index('key_idx', 'cache_key'),
3657 Index('cache_args_idx', 'cache_args'),
3657 3658 base_table_args,
3658 3659 )
3659 3660
@@ -3661,7 +3662,6 b' class CacheKey(Base, BaseModel):'
3661 3662
3662 3663 # namespaces used to register process/thread aware caches
3663 3664 REPO_INVALIDATION_NAMESPACE = 'repo_cache:{repo_id}'
3664 SETTINGS_INVALIDATION_NAMESPACE = 'system_settings'
3665 3665
3666 3666 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
3667 3667 cache_key = Column("cache_key", String(255), nullable=True, unique=None, default=None)
General Comments 0
You need to be logged in to leave comments. Login now